• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Button Renderer problem in Java swings

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can anyone help me out in this?

Regards,
Kannan Somaiah
 
Author
Posts: 974
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic