Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Button Renderer problem in Java swings

 
Kannan Somaiah
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on Java swings. I have a case wherein I have a JButton present inside a JTable.

I have also written a ButtonRenderer for the same.

Problem I am facing now is that I am not able to click the button .. In simple words focus is not coming to the button when I click on... but somehow if I get the focus on the button(with the use of tab key), I am able to click the button.

Hope I made the issue clear.

Can anyone help me in this?

My renderer code is below

Thanks in advance,
Kannan Somaiah

package com.emirates.res.easymars.ui.fares;

import java.awt.Component;

import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import com.emirates.res.easymars.core.ui.CCGUIButton;

public class CCGUIButtonRenderer implements TableCellRenderer {

String[] interfaces;
CCGUIButton button;
public CCGUIButtonRenderer(String[]interfaces) {
//setOpaque(true);
//super("Hello");
this.interfaces = interfaces;
}

public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {

if(column == 3 && row == 0) {
button = new CCGUIButton(interfaces[0], interfaces[0]);
button.setText(interfaces[0]);
}if(column == 3 && row == 1) {
button = new CCGUIButton(interfaces[1], interfaces[1]);
button.setText(interfaces[1]);
}if(column == 3 && row == 2) {
button = new CCGUIButton(interfaces[2], interfaces[2]);
button.setText(interfaces[2]);
}if(column == 3 && row == 3) {
button = new CCGUIButton(interfaces[3], interfaces[3]);
button.setText(interfaces[3]);
}
return button;
}
}
 
Kannan Somaiah
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone help me out in this?

Regards,
Kannan Somaiah
 
Brian Cole
Author
Ranch Hand
Posts: 923
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kannan Somaiah:
I am working on Java swings. I have a case wherein I have a JButton present inside a JTable.

I have also written a ButtonRenderer for the same.

Problem I am facing now is that I am not able to click the button .. In simple words focus is not coming to the button when I click on...


You need to write a cell editor in addition to the cell renderer.

but somehow if I get the focus on the button(with the use of tab key), I am able to click the button.


If you're not using a cell editor for the cell with the button, I don't see how that could be.
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!