|
7 | 7 | import javax.swing.*; |
8 | 8 |
|
9 | 9 | public final class MainPanel extends JPanel { |
10 | | - private final JCheckBox borderCheck = new JCheckBox("OptionPane.buttonAreaBorder"); |
11 | | - private final JOptionPane op = new JOptionPane("message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION); |
12 | | - |
13 | | - public MainPanel() { |
| 10 | + private MainPanel() { |
14 | 11 | super(new BorderLayout()); |
15 | 12 |
|
16 | | - JPanel p1 = new JPanel(); |
17 | | - p1.add(new JButton(new AbstractAction("default") { |
18 | | - @Override public void actionPerformed(ActionEvent e) { |
19 | | - UIManager.getLookAndFeelDefaults().put("OptionPane.sameSizeButtons", false); |
20 | | - //JOptionPane.showConfirmDialog(getRootPane(), "message"); |
21 | | - //JOptionPane pane1 = new JOptionPane("message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION); |
22 | | - UIDefaults d = new UIDefaults(); |
23 | | - d.put("OptionPane.sameSizeButtons", false); |
24 | | - op.putClientProperty("Nimbus.Overrides", d); |
25 | | - op.putClientProperty("Nimbus.Overrides.InheritDefaults", true); |
26 | | - SwingUtilities.updateComponentTreeUI(op); |
27 | | - op.createDialog(getRootPane(), "title").setVisible(true); |
28 | | - } |
29 | | - })); |
30 | | - p1.add(new JButton(new AbstractAction("sameSizeButtons") { |
31 | | - @Override public void actionPerformed(ActionEvent e) { |
32 | | - //UIManager.getLookAndFeelDefaults().put("OptionPane.sameSizeButtons", true); |
33 | | - //UIManager.put("OptionPane.buttonAreaBorder", BorderFactory.createLineBorder(Color.RED, 10)); |
34 | | - //JOptionPane.showConfirmDialog(getRootPane(), "message"); |
35 | | - UIDefaults d = new UIDefaults(); |
36 | | - if (borderCheck.isSelected()) { |
37 | | - d.put("OptionPane.buttonAreaBorder", BorderFactory.createLineBorder(Color.RED, 10)); |
38 | | - } else { |
39 | | - d.put("OptionPane.buttonAreaBorder", BorderFactory.createEmptyBorder()); |
40 | | - } |
41 | | - d.put("OptionPane.sameSizeButtons", true); |
42 | | - op.putClientProperty("Nimbus.Overrides", d); |
43 | | - op.putClientProperty("Nimbus.Overrides.InheritDefaults", true); |
44 | | - SwingUtilities.updateComponentTreeUI(op); |
45 | | - op.createDialog(getRootPane(), "title").setVisible(true); |
| 13 | + JCheckBox borderCheck = new JCheckBox("OptionPane.buttonAreaBorder"); |
| 14 | + JOptionPane op = new JOptionPane("message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION); |
| 15 | + |
| 16 | + JButton button1 = new JButton("default"); |
| 17 | + button1.addActionListener(e -> { |
| 18 | + UIManager.getLookAndFeelDefaults().put("OptionPane.sameSizeButtons", false); |
| 19 | + //JOptionPane.showConfirmDialog(getRootPane(), "message"); |
| 20 | + //JOptionPane pane1 = new JOptionPane("message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION); |
| 21 | + UIDefaults d = new UIDefaults(); |
| 22 | + d.put("OptionPane.sameSizeButtons", false); |
| 23 | + op.putClientProperty("Nimbus.Overrides", d); |
| 24 | + op.putClientProperty("Nimbus.Overrides.InheritDefaults", true); |
| 25 | + SwingUtilities.updateComponentTreeUI(op); |
| 26 | + op.createDialog(getRootPane(), "title").setVisible(true); |
| 27 | + }); |
| 28 | + |
| 29 | + JButton button2 = new JButton("sameSizeButtons"); |
| 30 | + button2.addActionListener(e -> { |
| 31 | + //UIManager.getLookAndFeelDefaults().put("OptionPane.sameSizeButtons", true); |
| 32 | + //UIManager.put("OptionPane.buttonAreaBorder", BorderFactory.createLineBorder(Color.RED, 10)); |
| 33 | + //JOptionPane.showConfirmDialog(getRootPane(), "message"); |
| 34 | + UIDefaults d = new UIDefaults(); |
| 35 | + if (borderCheck.isSelected()) { |
| 36 | + d.put("OptionPane.buttonAreaBorder", BorderFactory.createLineBorder(Color.RED, 10)); |
| 37 | + } else { |
| 38 | + d.put("OptionPane.buttonAreaBorder", BorderFactory.createEmptyBorder()); |
46 | 39 | } |
47 | | - })); |
| 40 | + d.put("OptionPane.sameSizeButtons", true); |
| 41 | + op.putClientProperty("Nimbus.Overrides", d); |
| 42 | + op.putClientProperty("Nimbus.Overrides.InheritDefaults", true); |
| 43 | + SwingUtilities.updateComponentTreeUI(op); |
| 44 | + op.createDialog(getRootPane(), "title").setVisible(true); |
| 45 | + }); |
| 46 | + |
| 47 | + JPanel p1 = new JPanel(); |
| 48 | + p1.add(button1); |
| 49 | + p1.add(button2); |
48 | 50 |
|
49 | 51 | JPanel p2 = new JPanel(); |
50 | 52 | p2.add(borderCheck); |
|
0 commit comments