e.g. Calendar Search Help
You must enter a value before pressing Search
jgoodies_looks

Class: com.jgoodies.looks.demo.SplitTab   ©

 OK to copy?
001 /*
002  * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved.
003  *
004  * Redistribution and use in source and binary forms, with or without 
005  * modification, are permitted provided that the following conditions are met:
006  * 
007  *  o Redistributions of source code must retain the above copyright notice, 
008  *    this list of conditions and the following disclaimer. 
009  *     
010  *  o Redistributions in binary form must reproduce the above copyright notice, 
011  *    this list of conditions and the following disclaimer in the documentation 
012  *    and/or other materials provided with the distribution. 
013  *     
014  *  o Neither the name of JGoodies Karsten Lentzsch nor the names of 
015  *    its contributors may be used to endorse or promote products derived 
016  *    from this software without specific prior written permission. 
017  *     
018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
020  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
021  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
022  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
024  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
025  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
027  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
028  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
029  */
030 
031 package com.jgoodies.looks.demo;
032 
033 import java.awt.BorderLayout;
034 import java.awt.Dimension;
035 
036 import javax.swing.*;
037 import javax.swing.tree.DefaultMutableTreeNode;
038 import javax.swing.tree.DefaultTreeModel;
039 import javax.swing.tree.TreeModel;
040 
041 import com.jgoodies.forms.factories.Borders;
042 import com.jgoodies.looks.LookUtils;
043 import com.jgoodies.uif_lite.component.UIFSplitPane;
044 
045 /** 
046  * Contains nested split panels and demonstrates how ClearLook
047  * removes obsolete decorations.
048  * 
049  * @author Karsten Lentzsch
050  * @version $Revision: 1.2 $
051  * 
052  * @see UIFSplitPane
053  */
054 final class SplitTab {
055     
056 
057     /**
058      * Builds and returns the panel.
059      */
060     JComponent build() {
061         JPanel panel = new JPanel(new BorderLayout());
062         panel.setOpaque(false);
063         panel.setBorder(Borders.DIALOG_BORDER);
064         panel.add(buildHorizontalSplit());
065         return panel;
066     }
067     
068 
069     /**
070      * Builds and returns the horizontal split using stripped split panes.<p>
071      * 
072      * Nesting split panes often leads to duplicate borders. 
073      * However, a look&feel should not remove borders completely
074      * - unless he has good knowledge about the context: the surrounding 
075      * components in the component tree and the border states.
076      */
077     private JComponent buildHorizontalSplit() {
078         JComponent left = new JScrollPane(buildTree());
079         left.setPreferredSize(new Dimension(200, 100));
080 
081         JComponent upperRight = new JScrollPane(buildTextArea());
082         upperRight.setPreferredSize(new Dimension(100, 100));
083 
084         JComponent lowerRight = new JScrollPane(buildTable());
085         lowerRight.setPreferredSize(new Dimension(100, 100));
086 
087         JSplitPane verticalSplit = UIFSplitPane.createStrippedSplitPane(
088                     JSplitPane.VERTICAL_SPLIT, 
089                     upperRight, 
090                     lowerRight);
091         JSplitPane horizontalSplit = UIFSplitPane.createStrippedSplitPane(
092             JSplitPane.HORIZONTAL_SPLIT,
093             left,
094             verticalSplit);
095         return horizontalSplit;
096     }
097     
098 
099     /**
100      * Builds and returns a sample tree.
101      */
102     private JTree buildTree() {
103         JTree tree = new JTree(createSampleTreeModel());
104         tree.expandRow(3);
105         tree.expandRow(2);
106         tree.expandRow(1);
107         return tree;
108     }
109 
110     
111     /**
112      * Builds and returns a sample text area.
113      */
114     private JTextArea buildTextArea() {
115         JTextArea area = new JTextArea();
116         area.setText(
117             "May\nI\nKindly\nRemind you that a\nMargin\nImproves a text's readability.");
118         return area;
119     }
120     
121 
122     /**
123      * Builds and returns a sample table.
124      */
125     private JTable buildTable() {
126         JTable table =
127             new JTable(
128                 createSampleTableData(),
129                 new String[] { "Artist", "Title      " });
130 
131         table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
132         table.getColumnModel().getColumn(0).setPreferredWidth(100);
133         table.getColumnModel().getColumn(1).setPreferredWidth(300);
134         table.setRowSelectionInterval(2, 2);
135         int tableFontSize    = table.getFont().getSize();
136         int minimumRowHeight = tableFontSize + 6;
137         int defaultRowHeight = LookUtils.IS_LOW_RESOLUTION ? 17 : 18;
Rate138         table.setRowHeight(Math.max(minimumRowHeight, defaultRowHeight));
139         return table;
140     }
141 
142     
143     /**
144      * Creates and returns a sample tree model.
145      */
146     private TreeModel createSampleTreeModel() {
147         DefaultMutableTreeNode root = new DefaultMutableTreeNode("Musicians");
148         DefaultMutableTreeNode parent;
149 
150         //
151         parent = new DefaultMutableTreeNode("Drums");
152         root.add(parent);
153         parent.add(new DefaultMutableTreeNode("Elvin Jones"));
154         parent.add(new DefaultMutableTreeNode("Jack DeJohnette"));
155         parent.add(new DefaultMutableTreeNode("Rashied Ali"));
156 
157         //
158         parent = new DefaultMutableTreeNode("Piano");
159         root.add(parent);
160         parent.add(new DefaultMutableTreeNode("Alexander von Schlippenbach"));
161         parent.add(new DefaultMutableTreeNode("McCoy Tyner"));
162         parent.add(new DefaultMutableTreeNode("Sun Ra"));
163 
164         parent = new DefaultMutableTreeNode("Saxophon");
165         root.add(parent);
166         parent.add(new DefaultMutableTreeNode("Albert Ayler"));
167         parent.add(new DefaultMutableTreeNode("Archie Shepp"));
168         parent.add(new DefaultMutableTreeNode("Charlie Parker"));
169         parent.add(new DefaultMutableTreeNode("John Coltrane"));
170         parent.add(new DefaultMutableTreeNode("Ornette Coleman"));
171         parent.add(new DefaultMutableTreeNode("Pharoa Sanders"));
172         parent.add(new DefaultMutableTreeNode("Sonny Rollins"));
173 
174         return new DefaultTreeModel(root);
175     }
176 
177     
178     /**
179      * Creates and returns sample table data.
180      */
181     private String[][] createSampleTableData() {
182         return new String[][] { 
183             { "Albert Ayler",   "Greenwich Village"         }, 
184             { "Carla Bley",     "Escalator Over the Hill"   }, 
185             { "Frank Zappa",    "Yo' Mama"                  },
186             { "John Coltrane",  "Ascension"                 }, 
187             { "Miles Davis",    "In a Silent Way"           }, 
188             { "Pharoa Sanders", "Karma"                     }, 
189             { "Wayne Shorter",  "Juju"                      },
190             { "",               ""                          },
191             { "",               ""                          },
192             { "",               ""                          },
193             { "",               ""                          },
194             { "",               ""                          },
195             { "",               ""                          },
196             { "",               ""                          },
197             { "",               ""                          },
198             { "",               ""                          },
199         };
200     }
201 
202 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
138 0% of 0