participate


Swing - jComboBox Renderer from two different entities (database tables)
This question is not answered.

<<   Back to Forum  |   Give us Feedback
This topic has 3 replies on 1 page.
diasks2
Posts:2
Registered: 11/3/09
jComboBox Renderer from two different entities (database tables)   
Nov 3, 2009 1:49 AM
 
 
I am able render a jComboBox as shown in this tutorial:

http://www.netbeans.org/kb/docs/java/gui-db-custom.html

public class ClassIDCellRenderer extends DefaultListCellRenderer {
 
@Override
    public Component getListCellRendererComponent(
            JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        if (value instanceof TableA) {
            TableA t = (TableA) value;
            setText(n.getname());
        }
        return this;
    }
}


However, I would like to be able to render the jComboBox with data from two different tables instead of just one. For example the above code is pulling from TableA. What if I wanted a concatenated value in the jComboBox that is pulling from both TableA and a TableB?

Thanks in advance for your help
-Kevin
 
kopik
Posts:110
Registered: 11/15/08
Re: jComboBox Renderer from two different entities (database tables)   
Nov 3, 2009 4:39 AM (reply 1 of 3)  (In reply to original post )
 
 
hii,

sry guy, for this silence about your question, that's JPA relevant, wiki.netbeans sites???

... kopik
 
camickr
Posts:32,733
Registered: 2/27/98
Re: jComboBox Renderer from two different entities (database tables)   
Nov 3, 2009 8:20 AM (reply 2 of 3)  (In reply to original post )
 
 
The data to be renderered should be stored in the same comboBox model. So store an Object in the model containing both pieces of information. See this posting for a simple example.
 
diasks2
Posts:2
Registered: 11/3/09
Re: jComboBox Renderer from two different entities (database tables)   
Nov 3, 2009 3:49 PM (reply 3 of 3)  (In reply to #2 )
 
 
Thanks for your reply camickr. I really appreciate it, I played around with that example for awhile, but I am still having trouble implementing what I want to do. Let me ask the question in a different way.

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.

public class ClassIDCellRenderer extends DefaultListCellRenderer {
 
@Override
    public Component getListCellRendererComponent(
            JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  
        if (value != null)
			{
				Tablea a = (Tablea)value;
                                Tableb b = (Tableb)value;
				setText( a.getName() + " " + b.getDayofweek() + " " + b.getLength() );
			}
 
			return this;
		}
	}


Thanks again for your help. Sorry I didn't catch on to the first example.

-Kevin
 
This topic has 3 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums