1 30 31 package com.jgoodies.looks.demo; 32 33 import java.awt.BorderLayout ; 34 import java.awt.Dimension ; 35 36 import javax.swing.*; 37 import javax.swing.tree.DefaultMutableTreeNode ; 38 import javax.swing.tree.DefaultTreeModel ; 39 import javax.swing.tree.TreeModel ; 40 41 import com.jgoodies.forms.factories.Borders; 42 import com.jgoodies.looks.LookUtils; 43 import com.jgoodies.uif_lite.component.UIFSplitPane; 44 45 54 final class SplitTab { 55 56 57 60 JComponent build() { 61 JPanel panel = new JPanel(new BorderLayout ()); 62 panel.setBorder(Borders.DIALOG_BORDER); 63 panel.add(buildHorizontalSplit()); 64 return panel; 65 } 66 67 68 76 private JComponent buildHorizontalSplit() { 77 JComponent left = new JScrollPane(buildTree()); 78 left.setPreferredSize(new Dimension (200, 100)); 79 80 JComponent upperRight = new JScrollPane(buildTextArea()); 81 upperRight.setPreferredSize(new Dimension (100, 100)); 82 83 JComponent lowerRight = new JScrollPane(buildTable()); 84 lowerRight.setPreferredSize(new Dimension (100, 100)); 85 86 JSplitPane verticalSplit = UIFSplitPane.createStrippedSplitPane( 87 JSplitPane.VERTICAL_SPLIT, 88 upperRight, 89 lowerRight); 90 return UIFSplitPane.createStrippedSplitPane( 91 JSplitPane.HORIZONTAL_SPLIT, 92 left, 93 verticalSplit); 94 } 95 96 97 100 private JTree buildTree() { 101 JTree tree = new JTree(createSampleTreeModel()); 102 tree.expandRow(3); 103 tree.expandRow(2); 104 tree.expandRow(1); 105 return tree; 106 } 107 108 109 112 private JTextArea buildTextArea() { 113 JTextArea area = new JTextArea(); 114 area.setText( 115 "May\nI\nKindly\nRemind you that a\nMargin\nImproves a text's readability."); 116 return area; 117 } 118 119 120 123 private JTable buildTable() { 124 JTable table = 125 new JTable( 126 createSampleTableData(), 127 new String [] { "Artist", "Title " }); 128 129 table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 130 table.getColumnModel().getColumn(0).setPreferredWidth(100); 131 table.getColumnModel().getColumn(1).setPreferredWidth(300); 132 table.setRowSelectionInterval(2, 2); 133 int tableFontSize = table.getFont().getSize(); 134 int minimumRowHeight = tableFontSize + 6; 135 int defaultRowHeight = LookUtils.IS_LOW_RESOLUTION ? 17 : 18; 136 table.setRowHeight(Math.max(minimumRowHeight, defaultRowHeight)); 137 return table; 138 } 139 140 141 144 private TreeModel createSampleTreeModel() { 145 DefaultMutableTreeNode root = new DefaultMutableTreeNode ("Musicians"); 146 DefaultMutableTreeNode parent; 147 148 parent = new DefaultMutableTreeNode ("Drums"); 150 root.add(parent); 151 parent.add(new DefaultMutableTreeNode ("Elvin Jones")); 152 parent.add(new DefaultMutableTreeNode ("Jack DeJohnette")); 153 parent.add(new DefaultMutableTreeNode ("Rashied Ali")); 154 155 parent = new DefaultMutableTreeNode ("Piano"); 157 root.add(parent); 158 parent.add(new DefaultMutableTreeNode ("Alexander von Schlippenbach")); 159 parent.add(new DefaultMutableTreeNode ("McCoy Tyner")); 160 parent.add(new DefaultMutableTreeNode ("Sun Ra")); 161 162 parent = new DefaultMutableTreeNode ("Saxophon"); 163 root.add(parent); 164 parent.add(new DefaultMutableTreeNode ("Albert Ayler")); 165 parent.add(new DefaultMutableTreeNode ("Archie Shepp")); 166 parent.add(new DefaultMutableTreeNode ("Charlie Parker")); 167 parent.add(new DefaultMutableTreeNode ("John Coltrane")); 168 parent.add(new DefaultMutableTreeNode ("Ornette Coleman")); 169 parent.add(new DefaultMutableTreeNode ("Pharoa Sanders")); 170 parent.add(new DefaultMutableTreeNode ("Sonny Rollins")); 171 172 return new DefaultTreeModel (root); 173 } 174 175 176 179 private String [][] createSampleTableData() { 180 return new String [][] { 181 { "Albert Ayler", "Greenwich Village" }, 182 { "Carla Bley", "Escalator Over the Hill" }, 183 { "Frank Zappa", "Yo' Mama" }, 184 { "John Coltrane", "Ascension" }, 185 { "Miles Davis", "In a Silent Way" }, 186 { "Pharoa Sanders", "Karma" }, 187 { "Wayne Shorter", "Juju" }, 188 { "", "" }, 189 { "", "" }, 190 { "", "" }, 191 { "", "" }, 192 { "", "" }, 193 { "", "" }, 194 { "", "" }, 195 { "", "" }, 196 { "", "" }, 197 }; 198 } 199 200 } | Popular Tags |