1 30 31 import java.awt.BorderLayout ; 32 import java.awt.Component ; 33 import java.awt.Dimension ; 34 import java.awt.Frame ; 35 36 import javax.swing.*; 37 import javax.swing.border.EmptyBorder ; 38 39 import com.jgoodies.looks.FontSizeHints; 40 import com.jgoodies.looks.LookUtils; 41 import com.jgoodies.looks.Options; 42 43 44 53 public final class Tiny { 54 55 58 public static void main(String [] args) { 59 Tiny instance = new Tiny(); 60 instance.configureUI(); 61 instance.buildInterface(); 62 } 63 64 74 private void configureUI() { 75 UIManager.put(Options.USE_SYSTEM_FONTS_APP_KEY, Boolean.TRUE); 76 Options.setGlobalFontSizeHints(FontSizeHints.MIXED); 77 Options.setDefaultIconSize(new Dimension (18, 18)); 78 79 String lafName = 80 LookUtils.IS_OS_WINDOWS_XP 81 ? Options.getCrossPlatformLookAndFeelClassName() 82 : Options.getSystemLookAndFeelClassName(); 83 84 try { 85 UIManager.setLookAndFeel(lafName); 86 } catch (Exception e) { 87 System.err.println("Can't set look & feel:" + e); 88 } 89 } 90 91 95 private void buildInterface() { 96 JFrame frame = new JFrame(); 97 frame.setJMenuBar(buildMenuBar()); 98 frame.setContentPane(buildContentPane()); 99 frame.setSize(600, 400); 100 locateOnScreen(frame); 101 frame.setTitle("JGoodies :: Tiny"); 102 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 103 frame.setVisible(true); 104 } 105 106 109 private void locateOnScreen(Frame frame) { 110 Dimension paneSize = frame.getSize(); 111 Dimension screenSize = frame.getToolkit().getScreenSize(); 112 frame.setLocation( 113 (screenSize.width - paneSize.width) / 2, 114 (screenSize.height - paneSize.height) / 2); 115 } 116 117 120 private JMenuBar buildMenuBar() { 121 JMenu menu; 122 JMenuBar menuBar = new JMenuBar(); 123 menuBar.putClientProperty(Options.HEADER_STYLE_KEY, Boolean.TRUE); 124 125 menu = new JMenu("File"); 126 menu.add(new JMenuItem("New...")); 127 menu.add(new JMenuItem("Open...")); 128 menu.add(new JMenuItem("Save")); 129 menu.addSeparator(); 130 menu.add(new JMenuItem("Print...")); 131 menuBar.add(menu); 132 133 menu = new JMenu("Edit"); 134 menu.add(new JMenuItem("Cut")); 135 menu.add(new JMenuItem("Copy")); 136 menu.add(new JMenuItem("Paste")); 137 menuBar.add(menu); 138 139 return menuBar; 140 } 141 142 145 private JComponent buildContentPane() { 146 JPanel panel = new JPanel(new BorderLayout ()); 147 panel.add(buildToolBar(), BorderLayout.NORTH); 148 panel.add(buildSplitPane(), BorderLayout.CENTER); 149 panel.add(buildStatusBar(), BorderLayout.SOUTH); 150 return panel; 151 } 152 153 156 private Component buildToolBar() { 157 JToolBar toolBar = new JToolBar(); 158 toolBar.putClientProperty(Options.HEADER_STYLE_KEY, Boolean.TRUE); 159 160 toolBar.add(createCenteredLabel("Tool Bar")); 161 return toolBar; 162 } 163 164 167 private Component buildSplitPane() { 168 JSplitPane splitPane = 169 new JSplitPane( 170 JSplitPane.HORIZONTAL_SPLIT, 171 buildSideBar(), 172 buildMainPanel()); 173 return splitPane; 174 } 175 176 179 private Component buildSideBar() { 180 return createStrippedScrollPane(new JTree()); 181 } 182 183 186 private Component buildMainPanel() { 187 JEditorPane editor = new JEditorPane(); 188 editor.setText( 189 "This is a minimal Swing application, that demos,\n" + 190 "how to install and use a JGoodies look&feel\n" + 191 "in a Swing application."); 192 return createStrippedScrollPane(editor); 193 } 194 195 198 private Component buildStatusBar() { 199 JPanel statusBar = new JPanel(new BorderLayout ()); 200 statusBar.add(createCenteredLabel("Status Bar")); 201 return statusBar; 202 } 203 204 206 209 private JScrollPane createStrippedScrollPane(Component c) { 210 JScrollPane scrollPane = new JScrollPane(c); 211 scrollPane.setBorder(null); 212 return scrollPane; 213 } 214 215 219 private Component createCenteredLabel(String text) { 220 JLabel label = new JLabel(text); 221 label.setHorizontalAlignment(SwingConstants.CENTER); 222 label.setBorder(new EmptyBorder (3, 3, 3, 3)); 223 return label; 224 } 225 226 } | Popular Tags |