Right Clicking on JButton

For Minesweeper game you have look for 1) JToggleButton 2) add Icon to JToggleButton methods JToggleButton#setIcon(); JToggleButton#setSelectedIcon(); JToggleButton#setDisabledIcon(); 3) add MouseListener to JToggleButton 4) override mouseClicked with method SwingUtilities.isRightMouseButton() inside result could be from code import java.awt.Insets; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.Icon; import javax.swing.JFrame; import javax.swing.JToggleButton; import javax.swing.SwingUtilities; import javax.swing.UIManager; public class MyToggleButton extends … Read more

Using setValueAt to recreate mutually exclusive check boxes

Don’t add your own MouseListener. Instead override setValueAt() in the TableModel to see the new value set by the default editor for Boolean.class. Addendum: Here’s an sscce. For expedience, it simply clears all entries in CHECK_COL, sets the new value and conditions the button accordingly. import java.awt.*; import javax.swing.*; import javax.swing.table.DefaultTableModel; /** * @see http://stackoverflow.com/questions/7920068 … Read more

Java swing JComponent “size”

As an alternative, consider the The Button API, which includes the method setRolloverIcon() “to make the button display the specified icon when the cursor passes over it.” Addendum: For example, import java.net.MalformedURLException; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class ButtonIconTest { public static void main(String[] args) … Read more