Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPopupMenu on a JTable Header Selection Problem  RSS feed

 
Eric Bresie
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working with a JPopupMenu added to a JTable's Header via the code provided.

When I right click on the header column, the popup menu shows correctly, but when I select away from it (right click elsewhere), the column header remains selected.

Project environment is using Java 5 on Windows XP (so , which may be part of my problem.

How do I get the column heading to lose focus (and not be selected) after selecting a menu item? Right now the only way seems to be when manually left clicking another column.

I tried adding an MouseListener to capture assorted mouse events but this did not seem to resolve the problem either.

I tried disabling column and row selection on the table but this did not help either.

Eric

 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't test your code because I don't use an IDE to generate code.

But I didn't notice that you assign the popup menu to 2 different components. Maybe this is causing some confusion.
 
Eric Bresie
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assigned the popup to the table and to the table's header so I get the popup when I right click in the table and when I click on the header.

Do you prefer the following code?

 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't use an IDE, so I still don't have access to the FrameView class.
 
Eric Bresie
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are part of the appframework.jar. Since I am using java5, I can't use the one provided with java6.

Alternative, see:
  • http://java.net/projects/appframework
  • http://java.net/projects/appframework/sources/svn/show/trunk/www/downloads?rev=151
  • http://kenai.com/projects/bsaf/pages/Home
  • http://kenai.com/projects/guts/pages/Home
  •  
    Darryl Burke
    Bartender
    Posts: 5167
    11
    Java Netbeans IDE Opera
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    No. Alternative, you see SSCCE. It only takes a few lines of code to create a JTable and display it in a JScrollPane in a JFrame. And the rest of the code will be a lot less convoluted. The setName(...) calls too are irrelevant to the stated problem and shouldn't appear in a SSCCE, nor should the JComboBox that appears to have no functionality in the posted code.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!