Zack Newsham
Zack Newsham

Reputation: 2982

JComboBox not painting

I am having an issue in an interface I am making in Java. It is working correctly for JPanel, JTextField, JCheckBox, JRadioButton and JButton, they all get painted correctly. But JComboBox does not. It only paints whatever background colour has been set.

Due to the projects complexity, none of these components are added to a container, but are virtually present, and are painted onto the container, other components are working, so I don't think that is the issue: Here is the creation code:

paintableComponent = new JComboBox(new String[]{"test"});

and the paint code, this is inside a pseudo component

if(this.getParentComponent() != null && this.getParentComponent() instanceof Component && !((Component)this.getParentComponent()).getValue("style.overflow").equals("visible")){
    g.setClip(this.getParentComponent().getX(), this.getParentComponent().getY(), this.getParentComponent().getWidth(), this.getParentComponent().getHeight());
}
Graphics oldG = g;
g = g.create(getX(), getY(), getWidth(), getHeight());
paintableComponent.paint(g);
g = oldG;
Iterator<Component> i = children.iterator();
while(i.hasNext()){
    i.next().paint(g);
}

Thanks in advance

Upvotes: 0

Views: 671

Answers (1)

StanislavL
StanislavL

Reputation: 57381

JComboBox has children components which have to be layed out. Try to call jComboInstance.setSize() before painting to let it layout children.

Upvotes: 3

Related Questions