aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes jComboBox Renderer from two different entities (database tables) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jComboBox Renderer from two different entities (database tables)" Watch "jComboBox Renderer from two different entities (database tables)" New topic
Author

jComboBox Renderer from two different entities (database tables)

Kevin Dias
Greenhorn

Joined: Nov 04, 2009
Posts: 5
I am able render a jComboBox as shown in this tutorial:

Netbeans Tutorial

However, I would like to be able to render the jComboBox with data from two different tables (entities) instead of just one.

So say I have the following tables:

CREATE TABLE A (
ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
NAME VARCHAR(50),
TYPE VARCHAR(50)
);

CREATE TABLE B (
ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
DAYOFWEEK VARCHAR(50),
LENGTH INT
);

In my ComboBox, I want it to display the NAME from TABLE A and the DAYOFWEEK and LENGTH from TABLE B

I was hoping something like the following would work, but it casts a class exception.



Any help or examples would be appreciated.
Thanks in advance
-Kevin
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
The OP has already been given advice to store the data to be rendered in a custom Object in the ComboBoxModel. Link to this posting was given as a simple example.
Kevin Dias
Greenhorn

Joined: Nov 04, 2009
Posts: 5
Thanks for your help Rob. I know you had referenced me to that example. Sorry for being thick, but I am having a hard time understanding how to translate that example into what I am trying to do. I am at novice at Java and programming in general (as you are well aware).

If you would be so kind as to translate that example into the short example I have in this thread I would be extremely grateful.

I will send you this gift basket for your time (just PM me your address):

[RP: removed linky]

Best,
Kevin
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
Start with building your custom Object using hard coded data.

Once you understand how that works you build the data using your custom SQL query.
Kevin Dias
Greenhorn

Joined: Nov 04, 2009
Posts: 5
I guess I am confused because (in the example you showed me) I don't understand how to get the ID and Description if they are coming from two different entities to render as the value in the combobox.

Therefore, I am humbly asking for someone to show me an example that is based on the (Table A/Table B) example in the first post.

I am willing to pay. Clearly, an easier solution than paypal or a money transfer is to send you a gift. So this is open to anyone on the forums who can provide me the answer. Rob, it seems like it is really easy for you and would take you 5 minutes. At the $30 dollar value of the gift, that would value your time at $360 per hour. I think that is a fair price for this type of question. And if you don't like the gift, just point me to something else you would like.

So, if anyone could help me I would greatly appreciate it.

-Kevin
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
I don't understand how to get the ID and Description if they are coming from two different entities to render as the value in the combobox.


Neither do I. You are in charge of the data. So you if you data is stored in a database, then you need to read up on SQL and learn how to build an SQL query that returns the data from two different tables in a single ResultSet. Then you build your custom object from the data in the ResultSet. This should be covered in any book on using SQL.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jComboBox Renderer from two different entities (database tables)