🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12454

Re: How to add a JButton to a cell of JTable?

#12454
From: apatil
Date: Tue, 05 Jan 1999 00:00
80 lines
2891 bytes

Hi

You can have JButton in a table. JTable has a DefaultCellEditor  which
takes only textfield,combo & Checkbox .  So if  u want to  have
component  other  than this, u need to create an editor which implements
TableCellEditor interface.

For a  Button

  create a subclass  of JButton and implement TableCellEditor interface

Pseudocode
  public  class ButtonEditor extends JButton implement TableCellEditor
 {
   ButtonEditor ()
       public Object getCellEditorValue()

 public Component getTableCellEditorComponent(JTable table,
                                                     Object value,
                                                     boolean sSelected,
                                                     int row,
                                                     int column) {


          this.aValue = value;
          this.setText(value.toString());
          this.setBorderPainted(false);
          this.setMargin(new Insets(0,0,0,0));

         value = " ";
         return this;

        }

   Similarly override the other methods

 and then call setCellEditor(new ButtonEditor()) for table column



Ajay




In article <76on45$76h4@forums.borland.com>,
  "Matt Krevs" <mattkrevs@flex.com.au> wrote:
> Look at the following link. It gives some good examples of
> TableCellRenderers and TableCellEditors. This sounds like what you want to
> do
>
> http://java.sun.com/docs/books/tutorial/ui/swingComponents/table.html
>
> Mario Christ wrote in message <3687B08F.3DE9C3F3@rz.hu-berlin.de>...
> >Hi,
> >
> >I really need this information for my thesis. I've tried to find the
> >solution by myself. However, I got stuck ofter a while:
> >
> >How do I add a JButton to a cell of a JTable???
> >
> >Unfortunately, only text, comboboxes and booleans can be added to a
> >JTable easily... it should be a little bit more complicated with a
> >Button.
> >
> >thank you in advance...
> >
> >Mario
> >
> >PS:
> >Please (!) send your answer to my mailbox as well.
> >
> >
>
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
Technical Details
Message-ID: <76sfsd$h4j$1@nnrp1.dejanews.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3687B08F.3DE9C3F3@rz.hu-berlin.de> <76on45$76h4@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,5ecb4afb31fd709d
X-Google-Attributes: gid111d45,public
From: apatil@digit.com
Subject: Re: How to add a JButton to a cell of JTable?
Date: 1999/01/05
Message-ID: <76sfsd$h4j$1@nnrp1.dejanews.com>
X-Deja-AN: 428922183
References: <3687B08F.3DE9C3F3@rz.hu-berlin.de> <76on45$76h4@forums.borland.com>
X-Http-Proxy: 1.0 x5.dejanews.com:80 (Squid/1.1.22) for client 199.190.198.20
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Tue Jan 05 07:44:13 1999 GMT
Newsgroups: borland.public.jbuilder.java.swing
X-Http-User-Agent: Mozilla/4.05 [en] (WinNT; I)