Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which JTable has the focus

Status
Not open for further replies.

keenanbr

Programmer
Oct 3, 2001
469
IE
Hi, I'm new to java. I am writing an application (converting from vb.net). So far (amongst others) I have a Jmenu and JtabbedPane. On each tab there are either 1 or two tables (JTable) which are populated from xml. In the menu there are options to insert/delete into/from table. I can tell which tab I am on but is there a way I can tell which table has the focus?

Regards,
 
I don't understand the question. What do you mean by "Be on"?
 
Yes I did but it doesn't give me what I need. I am currently playing around with;

KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener(new FocusChangeListener());

I think this might give me what I want. I will let you know how I get on.
 
Hi,

I have each table on a JPanel.

I setup a mouse listener on each panel. When the user clicks on the panel I set the focus on the panel.

With my KeyboardFocusManager I know the name of the panel that has the focus and so can insert/delete to/from the appropriate table.

Not sure if this is the best solution but it works.
 
I understand now. I don't see any problems to your solution, just a question: when the user clicks the panel it isn't automatically focused?

Cheers,
Dian
 
when the user clicks the panel it isn't automatically focused?

I would have thought so too but it doesn't appear to be. I am still experimenting
 
Yes, I am using that but I then have 2 panels on each tab and I need to allow the user to focus on either and then insert or delete to the associated table.
 
Maybe you can add a FocusListener to each JTable so you will be informed about when they lose or gain the focus

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top