Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2252
| From | "malpropio" <malpropio@THRWHITE.remove-dii-this> |
|---|---|
| Subject | CustomRenderer for enum |
| Message-ID | <1187195884.560233.250280@50g2000hsm.googlegroups.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| Date | 2011-04-27 15:38 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
hi everyone , I'm trying to create a customRenderer extending
JComboBox to display the different element of any enum. At this point
I created something that recognizes the enum and put the JComboBox in
the right Column but they are all empty. here is the code
import java.awt.Component;
import java.util.Vector;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import java.lang.Enum;
public class EnumRenderer<V extends Enum<V>> extends JComboBox
implements TableCellRenderer {
Class<V> valueType;
public EnumRenderer() {
// TODO Auto-generated constructor stub
}
public EnumRenderer(ComboBoxModel arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public EnumRenderer(Object[] arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public EnumRenderer(Vector<?> arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public EnumRenderer( Class<V> valueType ){
super();
System.out.println("Contructing the right Renderer");
this.valueType = valueType;
/*
for(V v : valueType.getEnumConstants()){
System.out.println("Adding element in the JComboBox");
addItem(v);
}
*/
}
@Override
public Component getTableCellRendererComponent(JTable arg0, Object
arg1,
boolean arg2, boolean arg3, int arg4, int arg5) {
// TODO Auto-generated method stub
if(arg1 != null /*&& arg1 instanceof Enum*/){
System.out.println(arg1);
Class<V> valueType = ((Enum)arg1).getDeclaringClass();
for(V v : valueType.getEnumConstants()){
addItem(v);
}
}
return this;
}
}
In my objects that get displayed in each row the getter of each field
gets call but I dont know how to make a getter for an enum that would
list the element in the enum or maybe I'm looking at the problem the
wrong way. Let me know what you think the best way to go is.
Thank you.
Dimitri
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Next in thread | Find similar | Unroll thread
CustomRenderer for enum "malpropio" <malpropio@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
Re: CustomRenderer for en "Ray Ma" <ray.ma@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
Re: CustomRenderer for en "malpropio" <malpropio@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
csiph-web