File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Repainting Problem (remove and add component) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Repainting Problem (remove and add component)" Watch "Repainting Problem (remove and add component)" New topic
Author

Repainting Problem (remove and add component)

dave tuazon
Greenhorn

Joined: Feb 26, 2002
Posts: 4
I have a problem with my code below. Everytime i uncheck the checkbox, the checkbox itself disappears. I have tried several things alrady (like setMinimumSize and setSize) for the panel where the checkbox is located. Can anyone please tell me what i could do to resolve the problem?
class userGUIFrame extends JFrame
{
public userGUIFrame()
{
setSize(300,200);
setTitle("Sample GUI");
setResizable(false);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});
contentPane = getContentPane();
/* Functions to add a scrollable status text area */
/* Tentatively creates a JList with and empty null model */
DefaultListModel model = new DefaultListModel();
logDisp = new JTextArea();
logDisp.setEditable(false);
scrollPane = new JScrollPane(logDisp);
/* Functions to add button to the JPanel */
JPanel actionPanel = new JPanel(new GridLayout(2,1));
/* Choice Panel */
JPanel choicePanel = new JPanel();
JCheckBox logCB;
logCB = addChoices(choicePanel,"Show Logs",true);
logCB.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent evt)
{
if (evt.getStateChange() == ItemEvent.DESELECTED)
{
contentPane.remove(scrollPane);
contentPane.setSize(300,150);
setSize(300,150);
}
else if (evt.getStateChange() == ItemEvent.SELECTED)
{
setSize(300,200);
contentPane.setSize(300,200);
contentPane.add(scrollPane,"Center");
}
contentPane.validate();
contentPane.repaint();
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.add(new JButton("OK"));
actionPanel.add(buttonPanel,"North");
actionPanel.add(choicePanel,"Center");
actionPanel.setMinimumSize(buttonPanel.getSize());
/* Populate the entire frame with the components */
contentPane.add(scrollPane,"Center");
contentPane.add(actionPanel,"South");
}
private JCheckBox addChoices(Container c,String caption,boolean selected)
{
JCheckBox checkBox = new JCheckBox(caption,selected);
c.add(checkBox);
return checkBox;
}
private Container contentPane;
private JScrollPane scrollPane;
public JTextArea logDisp;
}
dave tuazon
Greenhorn

Joined: Feb 26, 2002
Posts: 4
I was just wondering how come only the bottom part of the panel is affected (or at least the part where i add/remove the component until the bottom part).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Repainting Problem (remove and add component)