Here are my codes for adding the new component:
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (!todoListInput.getText().equals("")) {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
panel.setBackground(new Color(213, 134, 145, 55));
JCheckBox checkBox = new JCheckBox("");
checkBox.setOpaque(false);
checkBox.setForeground(Color.WHITE);
//checkBox.setBorder(line);
panel.add(checkBox);
Border border = new LineBorder(Color.GRAY, 1, true);
Border margin = new EmptyBorder(10,10,10,10);
panel.setBorder(new CompoundBorder(margin, border));
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
mainList.add(panel, gbc, 0);
validate();
repaint();
todoListInput.setText("");
}
}
});
My problem is that when I do an "onmouseover" action to the checkbox, part of the the whole jFrame will be appeared behind the checkbox
I found that this only appear when I do checkBox.setOpaque(false) or checkBox.setBackground(new Color(122,122,122,55)).
May I know what is the problem of my code?