?
Solved

JComboBox dilemma in JTable

Posted on 2003-02-26
7
Medium Priority
?
423 Views
Last Modified: 2007-12-19
Hi,
I have multiple TableCellEditor for the columns in my JTable. Here is the structure of my JTable:

Column0(single-JComboBox)  
Column1(multi-JComboBox)  
Column2(String)
Column3(User input)
Column4(single-JComboBox)

Initially, the JTable only contains headers and empty cells. The user clicks cell(0, 0) to select from JComboBox's popup menu.

Column1 has 5 lists of choices for the JComboBox. Depending on what the user has selected in Column0's JComboBox, Column1 displays a JComboBox popup menu accordingly. Once the users clicks an item in Column1's JComboBox popup menu, Column2's value in the same row is set accordingly.

I create a TableCellEditor for row and it seems to work. However, when the user changes the selection in Column0 that contains a value, it doesn't affect Column1 until the user clicks the cell in Column1.

The problem is that the user has to click the cell to make the JComboBox visible. I don't want to set default selectedIndex for the JComboBox, so I paint the cell in Column1 to flag the user the change in Column0. Is there any better solution?

Thanks in advance.
0
Comment
Question by:vvstan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Expert Comment

by:ykaganov
ID: 8030854
override setValueAt method of your TableModel:

pubic void setValueAt(Object value, int row, int col) {
  super.setValueAt(value, row, col);

  if(col == 0) {
    Object value2 = someCustomLogic();
    // calculate the new value in Column1
    setValueAt(value2, row, 1);
  }
}

Then, in the JComboBox that renders the editor for Column1, override

getTableCellEditorComponent

to populate the values and update selections based on getValueAt(row, 0) before returning it.

Hope this helps,

- Eugene
0
 

Author Comment

by:vvstan
ID: 8041817
Hi Eugene,

I am trying to figure out how to apply your solution to my problem.

In your setValueAt method, I don't think that I can calculate the new value for the corresponding cell in Column1. I can provide a corresponding JComboBox list but again, the user has to click on the corresponding cell in Column1 after changing the selection in Column0 to see the list, then the user can make the selection.

Right now I have an ActionListener for Column0 so Column1 will provide an appropriate JComboBox list accordingly but the user has to click the cell to make the JComboBox visible.

Thanks
0
 

Author Comment

by:vvstan
ID: 8041838
Hi Eugene,

I am trying to figure out how to apply your solution to my problem.

In your setValueAt method, I don't think that I can calculate the new value for the corresponding cell in Column1. I can provide a corresponding JComboBox list but again, the user has to click on the corresponding cell in Column1 after changing the selection in Column0 to see the list, then the user can make the selection.

Right now I have an ActionListener for Column0 so Column1 will provide an appropriate JComboBox list accordingly but the user has to click the cell to make the JComboBox visible.

Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Accepted Solution

by:
ykaganov earned 200 total points
ID: 8044195
If I understand your application logic correctly, the value selected in column0 drives the set of values selected in column1. So, if a user changes the selection in column0, he has to go and edit column1 next, right?

The only things you can do when value in Column0 changes is repopulate JComboBox list values for Column1, and either clear the Column1 field, or pick a default value from that list. The user still has to pick the right value from the list for Column1 as a separate step.

I think what you're trying to do is to pop up JComboBox for Column1 as soon as the user is done editing column0. I would suggest that you actually don't need to do that, just don't let the user proceed with your application until the table data is configured correctly (for example, if the table is in a dialog, don't enable "ok" button if column1 has any nulls in it). But I suppose you could add a listener to the table model that will invoke startEditing() on the column1 cell whenever the column0 changes, after you've done the model changes I suggested.

- Eugene
0
 

Expert Comment

by:CleanupPing
ID: 9059054
vvstan:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9672355
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept ykaganov's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question