Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using a JComboBox as a cell renderer in a JXTreeTable



Yvon,

Its best to think of the CellRenderers as a "stamping tool". Although the renderers are extended from Component, they aren't part of the Component heirarchy. The same renderer can be used over and over again to paint cells (by class or column). In other words, the render does not exist as a component but just the "image of a component". So you should see the combobox, but clicking on it will have no effect because its not a combobox, but just some pixels in a JTable. I'm afraid using an editor is the only sensible option.

By the way, you don't need to call super in the example you gave. It doesn't matter, but its unnecessary.

Regards,
Brendon.

On 13 Aug 2005, at 19:54, Yvon Thoraval wrote:

Hey all,

i'd like using a JComboBox as a cell renderer in a JXTreeTable.

i'm able to get the combo at the right place but the list items doesn't popup.

here is the piece of code :

<code>
public class SoilsRenderer extends DefaultTableCellRenderer {

    public SoilsRenderer() {}

public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
row, column);
if (value != null) {
ArrayList<Soil> soils = (ArrayList<Soil>) value;
ArrayList<String> sols = new ArrayList<String>();
for (int i = 0; i < soils.size(); i++) {
sols.add(((Soil) soils.get(i)).getType());
}
return new JComboBox(sols.toArray());
} else {
return new JLabel();
}
}
}
</code>


from print out i'm sure their is more than one item in the combo.

if i use the same combo as an editor, i get the popup, but here, i don't want to edit just to show multiple values...

also i use the same way to set an icon, no prob.

best,

Yvon


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >using a JComboBox as a cell renderer in a JXTreeTable (From: Yvon Thoraval <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.