I have some painting problems when I try to remove a certain componen from my container and add a new one.
I tried invoking the doLayout() and repaint() method wich seem to repaint the frame properly but whenever I resize the window (by pulling at the edge) the background turns back to white from my JTextArea.
Here is my current code:
public class ToolBarActionListener implements ActionListener {
private JFrame parent;
private Component component;
public ToolBarActionListener(JFrame parent) {
this.parent = parent;
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() instanceof ToolBarButton) {
ToolBarButton btn = (ToolBarButton)event.getSource();
if (btn.getName().equals("toolbar.stakes")) {
if (component != null) {
parent.getContentPane().remove(component);
}
component = new JTextArea();
parent.getContentPane().add(component, BorderLayout.CENTER);
}
if (btn.getName().equals("toolbar.contacts")) {
if (component != null) {
parent.getContentPane().remove(component);
}
component = new SomeCustomJPanel();
parent.getContentPane().add(component, BorderLayout.CENTER);
}
parent.repaint();
parent.getContentPane().repaint();
parent.doLayout();
parent.getContentPane().doLayout();
}
}
}
any idea how I can properly do this?