1 14 package wingset; 15 16 import org.wings.*; 17 18 import java.awt.event.ActionEvent ; 19 import java.awt.event.ActionListener ; 20 21 import javax.swing.tree.DefaultTreeModel ; 22 23 24 28 public class ScrollPaneExample 29 extends WingSetPane 30 { 31 private ScrollPaneControls controls; 32 private STable table; 33 private STree tree; 34 private SScrollPane scrollPane; 35 36 public SComponent createExample() { 37 table = new STable(new TableExample.ROTableModel(15, 15)); 38 table.setShowAsFormComponent(true); 39 table.setDefaultRenderer(new TableExample.MyCellRenderer()); 40 41 tree = new STree(new DefaultTreeModel (HugeTreeModel.ROOT_NODE)); 42 tree.setName("tree"); 43 tree.setShowAsFormComponent(false); 44 45 scrollPane = new SScrollPane(table); 46 scrollPane.getHorizontalScrollBar().setBlockIncrement(3); 47 scrollPane.getVerticalScrollBar().setBlockIncrement(3); 48 49 ((SScrollBar) scrollPane.getHorizontalScrollBar()).setShowAsFormComponent(false); 50 ((SScrollBar) scrollPane.getVerticalScrollBar()).setShowAsFormComponent(false); 51 52 controls = new ScrollPaneControls(); 53 controls.addSizable(scrollPane); 54 55 SForm p = new SForm(new SBorderLayout()); 56 p.add(controls, SBorderLayout.NORTH); 57 p.add(scrollPane, SBorderLayout.CENTER); 58 return p; 59 } 60 61 64 protected void showInPane(SComponent comp) { 65 scrollPane.setViewportView(comp); 66 } 67 68 class ScrollPaneControls extends ComponentControls { 69 public ScrollPaneControls () { 70 final SCheckBox showAsFormComponent = new SCheckBox("Show as Form Component"); 71 showAsFormComponent.addActionListener(new ActionListener () { 72 public void actionPerformed(ActionEvent e) { 73 boolean selected = showAsFormComponent.isSelected(); 74 table.setShowAsFormComponent(selected); 75 ((SScrollBar)scrollPane.getHorizontalScrollBar()).setShowAsFormComponent( selected); 76 ((SScrollBar)scrollPane.getVerticalScrollBar()).setShowAsFormComponent(selected); 77 } 78 }); 79 add(showAsFormComponent); 80 81 final SCheckBox paging = new SCheckBox("Paged Scrolling"); 82 paging.addActionListener(new ActionListener () { 83 public void actionPerformed(ActionEvent e) { 84 boolean selected = paging.isSelected(); 85 ((SScrollPaneLayout)scrollPane.getLayout()).setPaging(selected); 86 } 87 }); 88 paging.setSelected(true); 89 add(paging); 90 91 final SRadioButton tableButton = new SRadioButton("table"); 92 final SRadioButton treeButton = new SRadioButton("tree"); 93 final SButtonGroup group = new SButtonGroup(); 94 group.add(tableButton); 95 group.add(treeButton); 96 tableButton.setSelected(true); 97 98 group.addActionListener(new ActionListener () { 99 public void actionPerformed(ActionEvent e) { 100 if (tableButton.isSelected()) { 101 showInPane(table); 102 } else { 103 showInPane(tree); 104 } 105 } 106 107 }); 108 add(tableButton); 109 add(treeButton); 110 } 111 } 112 } 113
| Popular Tags
|