FH-Hof Dialoge Richard Göbel
FH-Hof Inhalt JDialog Vordefinierte Dialoge File Browser
FH-Hof Dialogboxen - Unterklasse von JDialog: Attribute public class TestDialog extends JDialog { private JPanel contentPane; private JPanel buttonPanel = new JPanel(); private JButton doneButton = new JButton("Done"); private JButton abortButton = new JButton("Abort"); private JTextField textfield = new JTextField(20);
FH-Hof Dialogboxen - Unterklasse von JDialog: Konstruktor public TestDialog (Frame owner, String title) { super(owner, "TestDialog", true); // Modal! contentPane = (JPanel) getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.add(textfield); contentPane.add(buttonPanel); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.add(doneButton); buttonPanel.add(Box.createHorizontalGlue()); buttonPanel.add(abortButton);... pack(); }
FH-Hof Dialogboxen - Unterklasse von JDialog: Listener abortButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {... hier die Aktion... setVisible(false); } }); doneButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {... hier die Aktion... setVisible(false); } });
FH-Hof Vordefinierte Dialoge - Beispiel JOptionPane pane = new JOptionPane(); String sName = JOptionPane.showInputDialog("Name eingeben:");
FH-Hof Vordefinierte Dialoge - weitere Möglichkeiten showConfirmDialog(Component parentComponent, Object message) showInputDialog(Component parentComponent, Object message) showMessageDialog(Component parentComponent, Object message, String title, int messageType) showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue)
FH-Hof File Browser - Darstellung
FH-Hof File Browser - Datei laden File file; JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(getContentPane()); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); System.err.println("Loading: " + file.getName()); } else { System.err.println("Open command cancelled"); }
FH-Hof File Browser - Datei Speichern File file; JFileChooser fc = new JFileChooser(); int returnVal = fc.showSaveDialog(getContentPane()); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); System.err.println("Saving: " + file.getName()); } else { System.err.println("Open command cancelled"); }
FH-Hof JTreeModel Zeichenkette Objekt Zeichenkette Objekt Aufbau eines JTree - Klassen DefaultMutableTreeNode JTree