Komponenten zur Gestaltung des Layouts Richard Göbel
Inhalt JScrollPane JSplitPane Border „Look and Feel“
JScrollPane - Anwendungsbeispiel JTextArea
JScrollPane - Programmcode JTextArea ta = new JTextArea(5,20); JPanel contentPane; . . . contentPane = (JPanel) getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS)); contentPane.add(Box.createRigidArea(new Dimension(5,0))); contentPane.add(new JScrollPane(ta));
JSplitPane - Anwendungsbeispiel
JSplitPane - Programmcode JTextArea ta1 = new JTextArea(5,20); JTextArea ta2 = new JTextArea(5,20); JPanel contentPane; . . . contentPane = (JPanel) getContentPane(); contentPane.setLayout(new BoxLayout(contentPane,BoxLayout.X_AXIS)); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setTopComponent( new JScrollPane(ta1)); splitPane.setBottomComponent( new JScrollPane(ta2)); contentPane.add(new JScrollPane(splitPane));
Border - Beispiele LineBorder BevelBorder (raised) EtchedBorder (lowered)
Border - Programmcode JTextField tf = new JTextField(20); . . . Border lb = new LineBorder(Color.black); oder Border lb = new BevelBorder(BevelBorder.RAISED); Border lb = new EtchedBorder(EtchedBorder.LOWERED); tf.setBorder(lb);
Border - Weitere Möglichkeiten LineBorder für einen Rand aus einer einzelnen Linie. BevelBorder, bei der mit Hilfe einer perspektivischen Darstellung der Bereich hervorgehoben wird. EtchedBorder für eine 'gravierte' Linie als Rand. EmptyBorder zur Darstellung eines Bereichs ohne Rand. MatteBorder für einen Rahmen, der aus Wiederholungen eines Icons besteht. TitledBorder für einen Rahmen mit Titel CompoundBorder für Kombinationen von Rahmen
TitledBorder - Beispiel
TitledBorder - Programmcode JTextField tf = new JTextField(20); . . . Border eb = new EtchedBorder(); Border tb = new TitledBorder(eb, "Testtitel", TitledBorder.LEFT, TitledBorder.TOP ); tf.setBorder(tb); tf.setMinimumSize(new Dimension(100,40));
TitledBorder - Beispiele für Parameter Horizontale Ausrichtung (titleJustification) LEFT RIGHT CENTER Vertikale Ausrichtung (titlePosition) ABOVE_TOP TOP BELOW_TOP ABOVE_BOTTOM BOTTOM BELOW_BOTTOM
Look and Feel - Beispiele unter Windows Metal Windows Motif
Look and Feel: Programmcode try { UIManager.setLookAndFeel(<ClassName>); // falls nach Aufbau der Oberflaeche: SwingUtilities.updateComponentTreeUI(<JFrame>); <JFrame>.pack(); } catch (Exception e) { }
Look and Feel: Methoden und Klassen UIManager.getCrossPlatformLookAndFeelClassName() UIManager.getSystemLookAndFeelClassName() "javax.swing.plaf.metal.MetalLookAndFeel" "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" "com.sun.java.swing.plaf.motif.MotifLookAndFeel" "javax.swing.plaf.mac.MacLookAndFeel"