I have a problem with my Swing app. If i start my application and place my mouse pointer where the button is going to be, the upper JLabel goes on the button.
This is a picture showing my problem
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
defFont = new Font("Impact", Font.PLAIN, 32);
JPanel mainpanel = new JPanel();
mainpanel.setLayout(new BorderLayout());
mainpanel.setPreferredSize(new Dimension(480, 320));
mainpanel.setBackground(Color.white);
JLabel title = new JLabel("-----Title-----");
title.setFont(defFont);
title.setHorizontalAlignment(JLabel.CENTER);
JLabel footer = new JLabel("Footer");
footer.setFont(defFont.deriveFont(Font.TRUETYPE_FONT, 14f));
JPanel midPanel = new JPanel();
midPanel.setBackground(Color.GRAY);
midPanel.setLayout(new GridBagLayout());
JButton startGameButton = new JButton("New Game");
applySettings(startGameButton);
midPanel.add(startGameButton);
mainpanel.add(title, BorderLayout.NORTH);
mainpanel.add(midPanel, BorderLayout.CENTER);
mainpanel.add(footer, BorderLayout.PAGE_END);
add(mainpanel);
pack();
setVisible(true);
EDIT: Forget to paste in the applySettings method. The button has some styling on it, maybe the function, that makes it transparent is the problem.
I've tested the code a bit, and when i try to set the background color, it brokes.
private void applySettings(JButton button)
{
button.setPreferredSize(new Dimension(200, 100));
button.setFont(defFont.deriveFont(Font.TRUETYPE_FONT, 24f));
button.setBorder(BorderFactory.createLineBorder(Color.black, 2, true));
button.setFocusPainted(false);
button.setBackground(new Color(255, 255, 255, 100));
button.setContentAreaFilled(true);
}