Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding a conditional popup menu to a Jtable using Matisse in Netbeans?  RSS feed

 
Pete Dawson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to add a popup menu to a Jtable such that the menu only shows when a row is selected in the Jtable. Can anyone help me with how to do this,
I'm using the Matisse GUI builder in Netbeans 6.7.1
I can add a popup menu OK but it is possible to pull up the menu even when no table row is selected, this is what I am trying to avoid.

Thanks
Pete
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete,
Welcome to the Ranch.

How are you showing the popup? Have you used the JCOmponent#setComponentPopupMenu()? If yes, you will need to use mouse listeners and use the JPopupMenu#show() instead, which will be triggered only if any table row(s) is/are selected.
 
Pete Dawson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,

Yes the automatically generated code contains

jTable1.setComponentPopupMenu(jPopupMenu1);

So that means I need to back up a step and add the menu programmatically myself? GUI builders are a bit tricky when you can only do part of the job with them!

Pete
 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GUI builders are a bit tricky when you can only do part of the job with them!


Which is why people who want to learn Swing don't use them.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete,
To answer your question, yes. You will have to use the mouse listener approach.

I am with Rob here. IDEs which auto generate the code never give you the level of control which hand coding does (as you have found out yourself). Also, Netbeans generated code will not (always) work on other IDEs like say Eclipse.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!