Advertisement

06.18.2008 at 03:11PM PDT, ID: 23497112
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

JComboBox cell renderer/editor updates other JComboBox in same JTable

Asked by jolly_rog in Java AWT & Swing, Java Editors & IDEs

Tags:

I'm stuck. I have a JTable that holds a JComboBox which is populated depending on the value in another cell (plain) in the same row. Everything displays correctly, with the correct values in each combo box. The problem is when I make a selection on a combo box, any previous combo box selections revert to the default state. I know I'm stomping on either my combo box instance or the Vector I'm populating it with in either my cell editor or cell renderer class. I'm also fairly certain I'm implementing too many instances of JComboBox.

Thanks in advance....Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
 
public class ComboBoxTable extends JTable {
    
    public ComboBoxTable(TableModel tm) {
        super(tm);
        tableModel = (ComboBoxOutputTableModel)tm;
    }
    
    ComboBoxOutputTableModel tableModel;
    
    Vector valuesVector = null;
    
    
    public TableCellRenderer getCellRenderer(int row, int column){
        if(column == 1){
            setValuesVector(row,column);
            MyComboBoxRenderer renderer = new MyComboBoxRenderer(valuesVector);
            getColumnModel().getColumn(1).setCellRenderer(renderer);
            return renderer;
        }
        else return super.getCellRenderer(row, column);
    }
 
    public TableCellEditor getCellEditor(int row, int column)
    {       
        if (column == 1){           
            
            MyComboBoxEditor editor = new InegQueueComboBoxEditor(valuesVector);
            return editor;
        }
        else return super.getCellEditor(row, column);
    }
    
    /**
     * Gets the collection from the table model data for the current row and populates 
     * the Vector that will be set to a comboBox with it
     * tableModel.getData() returns Object[int][String[]]
     */
    public void setValuesVector(int row, int column){
        Object[] modelRow = tableModel.getData()[row];   
        this.valuesVector = new Vector((Vector)modelRow[column]);
    }
 
}
 
public class MyComboBoxRenderer implements TableCellRenderer {
   
    public MyComboBoxRenderer(Vector v){
 
    }
 
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        JComboBox comboBox = null;
               
        if(value == null){
            comboBox = new JComboBox();
        }else{
            Vector vector = (value instanceof Vector)?(Vector)value:new Vector();
            comboBox = new EiiComboBox(vector);
            comboBox.setFont(LookAndFeelConstants.getLabelFont());
        }
        if (isSelected) {
            comboBox.setForeground(table.getSelectionForeground());
            comboBox.setBackground(table.getSelectionBackground());
            
        } else {
            comboBox.setForeground(table.getForeground());
            comboBox.setBackground(table.getBackground());
        }
        return comboBox;
    }
    
}
 
 
public class MyComboBoxEditor extends AbstractCellEditor implements TableCellEditor {
 
    private Component comp = null;
    private int r = 0;
    private int c = 0;
   
    public MyComboBoxEditor(Vector items) {
        super();
    }
    
 
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        Component com = null;
        r = row;
        c = column;
        JComboBox comboBox;
        
        if(value == null || value.toString().length() == 0) com = new JTextField("");
        else if(value instanceof Vector){
            comboBox = new JComboBox();
              if(comboBox.getModel().getSize() > 0){
                    // clear it...
                  comboBox.removeAllItems();
              }
              comboBox.setModel(new DefaultComboBoxModel((Vector)value));
              
              comboBox.addItemListener(new ItemListener(){
                public void itemStateChanged(ItemEvent e) {
                
                	//nothing implemented here yet
                }                  
              });
 
              com = comboBox;
              
        }else {
        
            comboBox = new JComboBox();
              if(comboBox.getModel().getSize() > 0){
                    // clear it...
                  comboBox.removeAllItems();
              }
              comboBox.addItem(value);
              com = comboBox;
        }
        comp = com;
        return com;
    }
 
	//inherited
	
    public Object getCellEditorValue() {
        return null;
    }
}
 
 
[+][-]06.18.2008 at 03:15PM PDT, ID: 21817794

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.18.2008 at 05:12PM PDT, ID: 21818333

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.18.2008 at 05:49PM PDT, ID: 21818468

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.18.2008 at 05:53PM PDT, ID: 21818482

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 07:59AM PDT, ID: 21822788

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 08:39AM PDT, ID: 21823300

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 04:19PM PDT, ID: 21827291

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 07:18PM PDT, ID: 21827981

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 07:31PM PDT, ID: 21828033

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.20.2008 at 05:30AM PDT, ID: 21830520

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.20.2008 at 02:41PM PDT, ID: 21835147

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.20.2008 at 06:42PM PDT, ID: 21835994

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.21.2008 at 05:01PM PDT, ID: 21839242

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java AWT & Swing, Java Editors & IDEs
Tags: Java, Swing
Sign Up Now!
Solution Provided By: objects
Participating Experts: 1
Solution Grade: B
 
 
[+][-]06.21.2008 at 08:34PM PDT, ID: 21839583

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.22.2008 at 04:22PM PDT, ID: 21842640

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.25.2008 at 12:01PM PDT, ID: 21868812

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.25.2008 at 03:06PM PDT, ID: 21870276

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.30.2008 at 01:26PM PDT, ID: 21902741

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-38 / EE_QW_2_20070628