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 / March 2005

Tip: Looking for answers? Try searching our database.

How do I put a JCheckBox into a cell of a JTable?

Thread view: 
Mark Sizzler - 02 Mar 2005 22:03 GMT
When I google for "JTable JCheckbox cell" I get thousands of hits but they
do not explain on how to put a JCheckBox into all cells of a column and how
to retrieve the current status (checked/unchecked) from it.

As I understand I have to replace the current DefaultRenderer by
my own Renderer class. Currently my JTable is defined similar to:

        myJTable = new JTable(myTableModel) {
          public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component component = super.prepareRenderer(renderer,row,column);
            if (isRowSelected(row))
               component.setBackground(Color.blue);
            else if (((String)getValueAt(row,column)).equals("Test"))
             component.setBackground(Color.yellow);
          else
               component.setBackground(Color.white);
           
           return component; }
          };

How can I extend this code with the necessary JCheckBox additions?

Mark
hiwa - 03 Mar 2005 08:17 GMT
> When I google for "JTable JCheckbox cell" I get thousands of hits but they
> do not explain on how to put a JCheckBox into all cells of a column and how
[quoted text clipped - 19 lines]
>
> Mark

Renderer is useless because it is a rubber stamp on the screen,
not a real component.

See SwingSet2 source code that accompanies your JDK download.


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.