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 / August 2003

Tip: Looking for answers? Try searching our database.

[SWING] TableHeader with multiple JComponents

Thread view: 
Markus Mehlan - 15 Aug 2003 08:05 GMT
Hi,

i put a JPanel with a JButton and a JTextField in a the Header of a JTable.

Code-snippet:
----------------------
Enumeration enumeration = tableView.getColumnModel().getColumns();

while (enumeration.hasMoreElements()) {

   TableColumn aColumn = (TableColumn)enumeration.nextElement();

   aColumn.setHeaderRenderer(new TableHeaderFilter() );

}

In my TableHeaderFilter class i've overwritten the method
getTableCellRendererComponent.

The problem is that the JTextField and the JButton don't respond on
mouse-actions.

Has anyone an idee?

Thanks for your help,

Markus
Jacob - 15 Aug 2003 09:02 GMT
> Hi,
>
[quoted text clipped - 17 lines]
> The problem is that the JTextField and the JButton don't respond on
> mouse-actions.

The components you put in the header is just
there for rendering purposes. They have no
behaviour whatsoever.

It is a bit confusing. I've tried to decorate
table headers with sorting buttons and similar
features without any luck, until a realised
the fact. I've found no satisfying workaround.
Thomas Weidenfeller - 15 Aug 2003 10:18 GMT
> The components you put in the header is just
> there for rendering purposes. They have no
[quoted text clipped - 4 lines]
> features without any luck, until a realised
> the fact. I've found no satisfying workaround.

http://www2.gol.com/users/tame/swing/examples/JTableExamples5.html

has some examples. They are rather old, and I have no idea if they
still work.

/Thomas
Carsten Zerbst - 15 Aug 2003 10:26 GMT
> The problem is that the JTextField and the JButton don't respond on
> mouse-actions.
>
> Has anyone an idee?

The table header is getting the mouse events, not the individual
components.

It works like this:

========================

  table.getTableHeader(  ).addMouseListener( new TGHeaderListener(  ) );

public class TGHeaderListener extends MouseAdapter {
       public void mouseClicked( MouseEvent ev ) {
           if ( ev.getClickCount(  ) != 2 ) {
               return;
           }

        // sort this column ...
         
       }

       public void mousePressed( MouseEvent ev ) {
           maybeShowPopup( ev ); // Unix
       }

       public void mouseReleased( MouseEvent ev ) {
           maybeShowPopup( ev );
       }

       protected void maybeShowPopup( MouseEvent ev ) {

           //log.debug("maybeShowPopup " + ev );
           int col = table.columnAtPoint( ev.getPoint(  ) );
           log.debug( "col " + col );

           if ( ev.isPopupTrigger(  ) && ( col != -1 ) ) {
// create a popup menu on the column header
               JPopupMenu menu = new JPopupMenu(  );

               
               menu.show( ev.getComponent(  ), ev.getX(  ), ev.getY(  ) );
           }
       }
   }

==================

Bye, Carsten



Signature

Dipl. Ing. Carsten Zerbst         |   carsten.zerbst@atlantec-es.com

Markus Mehlan - 15 Aug 2003 22:14 GMT
> > The problem is that the JTextField and the JButton don't respond on
> > mouse-actions.
[quoted text clipped - 46 lines]
>
> Bye, Carsten

Hi, Carsten,

The table header really catches the events. But how can i dispatch them to
the different components in the JPanel?
The JButton should work like a normal Button not like a label.
When i click in The JTextField it should be possible to enter text,
etc.

thx Markus
Carsten Zerbst - 23 Aug 2003 21:39 GMT
> Hi, Carsten,
>
[quoted text clipped - 3 lines]
> When i click in The JTextField it should be possible to enter text,
> etc.

Hello Markus,

I'm afraid that you have to dispatch the events by yourself to the
desired widgets ...

I have implemented a kind of super table for our applications which
supports filtering and sorting. Filtering for a single column is done by
double clicking on the header, there is an extra field for single column
filtering as done in many email clients like evolution or kmail etc.
Sorting my multiple columns has an own toplevel started by a popup menu,
filtering using many criterias has an extra toplevel.

Bye, Carsten
Markus Mehlan - 27 Aug 2003 12:54 GMT
> Hello Markus,
>
[quoted text clipped - 9 lines]
>
> Bye, Carsten

Hello Carsten,

now i have a solution for my problem. It looks like this:
http://www.mmdev.it-pc.de/table1.jpg

I had to create my own TableHeader, a renderer and an editor for the
header cells, a renderer for the left Column and so on. It's a lot of work.
If you hav ean easier way to do this, tell it me.

Perhaps you can send me a screenshot of your "super  table".

thx, Markus


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.