I "think" what your talking about is the focus border used to show which button has focus...
Try using b1.setFocusPainted(false);
instead
For example...
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class ButtonRows {
public static void main(String[] args) {
new ButtonRows();
}
public ButtonRows() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());
for (int index = 0; index < 10; index++) {
JButton b1 = new JButton(Integer.toString(index));
b1.setFocusPainted(false);
b1.setBorder(BorderFactory.createEmptyBorder(2, 3, 2, 3));
b1.setContentAreaFilled(false);
frame.add(b1);
}
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
Also, the use of setSize
and setBounds
is scary, you should be letting the layout manager deal with these details.
I don't know why you're using a MouseListener
on button, but the prefered method for gaining notification for when a button is triggered is through the ActionListener
interface, as a button my a triggered via a number means, not just the mouse click
Take a closer look at How to Use Buttons for more details