Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

CheckBox renderer problem

Thread view: 
John M - 29 Jan 2004 18:48 GMT
Hello,

I made a jTable and add columns to it. One column is a checkbox column. I
made an editor and a renderer to it, but it doesn't work very well.
If I check in the checkbox in the last row and then click to an other cell
then all checkbox will be checked in.
What can I do?

I use the renderer as:
jTable1.getColumnModel().getColumn(pos).setCellRenderer(new
CheckBoxRenderer());

My renderer is:
public class CheckBoxRenderer extends JCheckBox implements TableCellRenderer
{

 public CheckBoxRenderer() {
   setOpaque(false);
 }

 public Component getTableCellRendererComponent(
     JTable table, Object value,
     boolean isSelected, boolean hasFocus,
     int row, int column) {
   if (value != null) {
     this.setSelected( ( (Boolean) value).booleanValue());
   }
   return this;
 }
}
Christian Kaufhold - 29 Jan 2004 19:02 GMT
> I made a jTable and add columns to it. One column is a checkbox column. I
> made an editor and a renderer to it, but it doesn't work very well.
> If I check in the checkbox in the last row and then click to an other cell
> then all checkbox will be checked in.

Impossible to say exactly without more code.

> public class CheckBoxRenderer extends JCheckBox implements TableCellRenderer
> {
>
>  public CheckBoxRenderer() {
>    setOpaque(false);

Use setContentAreaFilled. Is it not the default?

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

>    if (value != null) {
>      this.setSelected( ( (Boolean) value).booleanValue());

Do not leave the check box at its old state if 'value' is 'null'.

Either null is invalid, then remove the 'if', or null should be
treated as one of true/false.

If false (as usual), this can be written without casting:

      this.setSelected(Boolean.TRUE.equals(value));

(this will also allow other Objects then Booleans and treat them all as
false).

Christian
Marc Dzaebel - 29 Jan 2004 20:57 GMT
> Hello,
> then all checkbox will be checked in.

May be you reused the identical value object in different table cells? The
renderer is ok.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.