2

I need a Container with similar JPanels lined up one below the other which can be selected. I could:

  1. Use a JList with a custom renderer but those JPanels would be passive elements, that's not what I want.
  2. 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
  3. 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.

dStulle
  • 609
  • 5
  • 24
  • *"..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 01 '11 at 08:55

3 Answers3

2

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.

Nate W.
  • 9,141
  • 6
  • 43
  • 65
2

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

Table Button Column shows how you can do this.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
camickr
  • 321,443
  • 19
  • 166
  • 288
1

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

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319