Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ListCellRenderer problem (needing buttom support)  RSS feed

 
Melu Llovio
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my program, I define a
JList

, and set its
CellRenderer

with
MyRenderer

, where
MyRenderer

is a class that extends JPanel and implements ListCellRenderer.

So the code is as follows:

private static class ListCellRender extends JPanel implements ListCellRender



Here my problem is: if I add a JButton in MyRenderer, the button doesn't work at all. It seems that it is just painted on the JPanel and has no functionality. How can I make the button fire action event when I click it?

Thanks!
 
Nick Meverden
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why are you extending JPanel?

public class MyCustomRenderer extends JButton implements ListCellRenderer {
public Component getListCellRendererComponent(
Jlist list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {

if (isSelected) {
//JBUTTON ACTIONS HERE
} else {
//JBUTTON ACTIONS HERE
}

}



}
 
Nick Meverden
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forgot the "return this;" at the end of that sample code.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!