Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Jcomboboxes in jtable select the same value..

Reply
Thread Tools

Jcomboboxes in jtable select the same value..

 
 
6e
Guest
Posts: n/a
 
      07-29-2005
Hi,

Ive created a JTable that has one column that is full of JCombobox
objects.

The weird thing is that when I select one value in.. say row 3.., that
value is used not only in row 3, but also row 4,5, and 6 and all the
way to the bottom-1 of the table.

I created a custom celleditor and cellrenderer, code I included below
for your perusal...

--------main app code-------------
String[] values = new String[]{" ", "Heading", "Body"};

table.getColumnModel().getColumn(table.convertColu mnIndexToView(iFORMAT)).setCellEditor(new
ComboBoxEditor(values));

table.getColumnModel().getColumn(table.convertColu mnIndexToView(iFORMAT)).setCellRenderer(new
ComboBoxRenderer(values));



------------combobox editor---------------
public class ComboBoxEditor extends DefaultCellEditor {
public ComboBoxEditor(String[] items) {
super(new JComboBox(items));
}
}


--------------Combobox renderer----------
ublic class ComboBoxRenderer extends JComboBox implements
TableCellRenderer {
public ComboBoxRenderer(String[] items) {
super(items);
}

public Component getTableCellRendererComponent(JTable table, Object
value,
boolean isSelected, boolean hasFocus, int row, int column)
{
if (isSelected) {
setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground() );
} else {
setForeground(table.getForeground());
setBackground(table.getBackground());
}

// Select the current value
setSelectedItem(value);
return this;
}
}

 
Reply With Quote
 
 
 
 
jan V
Guest
Posts: n/a
 
      07-29-2005
> The weird thing is that when I select one value in.. say row 3.., that
> value is used not only in row 3, but also row 4,5, and 6 and all the
> way to the bottom-1 of the table.


Sounds like your combo boxes are sharing underlying data models...

> I created a custom celleditor and cellrenderer, code I included below
> for your perusal...
>
> --------main app code-------------
> String[] values = new String[]{" ", "Heading", "Body"};
>
>

table.getColumnModel().getColumn(table.convertColu mnIndexToView(iFORMAT)).se
tCellEditor(new
> ComboBoxEditor(values));
>
>

table.getColumnModel().getColumn(table.convertColu mnIndexToView(iFORMAT)).se
tCellRenderer(new
> ComboBoxRenderer(values));


You may get happier results if your renderers don't share the values
array...


 
Reply With Quote
 
 
 
 
6e
Guest
Posts: n/a
 
      07-29-2005
I appreciate the idea, I explored it previously by
new ComboBoxEditor( new String[]{" ", "Heading", "Body"}; ... but it
didn't seem to work...

unless I just don't understand what you're trying to tell me... If
this is the case, please explain further.. or let me know if you have
any other ideas?..

Thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two JComboBoxes One change to other RC Java 5 01-30-2008 10:16 AM
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
select box - using refresh to select same item twice entfred@hotmail.com Javascript 2 07-25-2006 11:54 PM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM



Advertisments