Active Elements in swing JTree, JTable or JList?

As you've discovered, simply putting a JPanel inside a JList doesn't quite work as you'd like. The JPanel will be passive and won't receive events - essentially all that is happening is your JPanel is simply being drawn, it's not a living component.

Up vote 2 down vote favorite share g+ share fb share tw.

I need a Container with similar JPanels lined up one below the other which can be selected. I could: Use a JList with a custom renderer but those JPanels would be passive elements, that's not what I want. Implement my own Container with 'active' JPanels but those would not be selectable.

Or could they made selectable? Maybe a MouseListener and access to the system default selected-background-colors could be a way but it seems a bit too much effort Use a JTable or JTree with custom cell editors rendering the 'active' JPanel. But these active parts would only react at the 'second' click, first to activate the editor, second to perform the real action of the JPanel.

This is also not acceptable. To get a more visual impression, here is an example of what this could mean: A JList containing list items which have each two functional JButtons. Java swing jtree jlist link|improve this question edited Aug 31 '11 at 22:32 asked Aug 31 '11 at 21:38dStulle12610 25% accept rate.

..a bit too much effort" Sometimes programmers have to put down the coffee & donuts & actually program. :( – Andrew Thompson Aug 31 '11 at 21:53 It is not like I want not to do this. But I prefer solutions where I can build on existing things instead of rewrite something already there.

– dStulle Aug 31 '11 at 22:30 regarding 3) when or whether editing is started is up to the implementation of CellRenderer: implement isCellEditable(EventObject) as needed – kleopatra Sep 1 '11 at 8:55.

As you've discovered, simply putting a JPanel inside a JList doesn't quite work as you'd like. The JPanel will be passive and won't receive events - essentially all that is happening is your JPanel is simply being drawn, it's not a living component. Instead of using a JList to put your panels in a list, use a list-like layout manager, such as BoxLayout or GridLayout.

If you want all your panels to be the same size, use GridLayout with only a single column. How to Use GridLayout How to use BoxLayout.

This would be my second point. And totally missing the selectability of the Items. – dStulle Aug 31 '11 at 22:34.

I'm not sure I understand your "example". If you want two functional buttons, then use a JTable where the funtional buttons are contained is separate columns. Then your data would be displayed in other columns.

Table Button Column shows how you can do this.

Your question(s) isn't clear for me, maybe here there is JTable, with one TableColumn but without TableHeader, contains JPanel with active JComponents inside (you can implements TableCellEditor for all JComponents) as JComboBox, JButton and JTextField.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions