Java Code Examples for javax.swing.JButton#addChangeListener()
The following examples show how to use
javax.swing.JButton#addChangeListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FatalErrorDialog.java From launcher with BSD 2-Clause "Simplified" License | 5 votes |
public FatalErrorDialog addButton(String message, Runnable action) { JButton button = new JButton(message); button.addActionListener(e -> action.run()); button.setFont(font); button.setBackground(DARK_GRAY_COLOR); button.setForeground(Color.LIGHT_GRAY); button.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, DARK_GRAY_COLOR.brighter()), new EmptyBorder(4, 4, 4, 4) )); button.setAlignmentX(Component.CENTER_ALIGNMENT); button.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); button.setFocusPainted(false); button.addChangeListener(ev -> { if (button.getModel().isPressed()) { button.setBackground(DARKER_GRAY_COLOR); } else if (button.getModel().isRollover()) { button.setBackground(DARK_GRAY_HOVER_COLOR); } else { button.setBackground(DARK_GRAY_COLOR); } }); rightColumn.add(button); rightColumn.revalidate(); return this; }
Example 2
Source File: FatalErrorDialog.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
public FatalErrorDialog addButton(String message, Runnable action) { JButton button = new JButton(message); button.addActionListener(e -> action.run()); button.setFont(font); button.setBackground(ColorScheme.DARK_GRAY_COLOR); button.setForeground(Color.LIGHT_GRAY); button.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, ColorScheme.DARK_GRAY_COLOR.brighter()), new EmptyBorder(4, 4, 4, 4) )); button.setAlignmentX(Component.CENTER_ALIGNMENT); button.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); button.setFocusPainted(false); button.addChangeListener(ev -> { if (button.getModel().isPressed()) { button.setBackground(ColorScheme.DARKER_GRAY_COLOR); } else if (button.getModel().isRollover()) { button.setBackground(ColorScheme.DARK_GRAY_HOVER_COLOR); } else { button.setBackground(ColorScheme.DARK_GRAY_COLOR); } }); rightColumn.add(button); rightColumn.revalidate(); return this; }