• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Repainting Problem (remove and add component)

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic