• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parent Frames and Panel

 
Rambo Rambabu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like to know if there is any way to find out the Frame, Panel etc for a given compomenent.
For Ex in the following
--------------------JFrame mainWindow-----------
------------------- JPanel myPanel-------------
--------------------JPanel statePanel---------
StateName: (JTextField) stateTextField
-----------------------------------------------
-----------------------------------------------
------------------------------------------------
I want to know the window(main window) that is holding my component stateTextField.
I need this as I am using MVC patterns and in the action package I am trying to show some dialog (model) windows and to show a dialog, I need to pass the frame as a parameter to the constructor and I don't know how to find the frame(main window).
I tried using component.getParent(), but this is always returning NULL and I getting null pointer excetptions.
thakyou,
Rambo
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, I can't help you with finding the parent frame of the component, but I wondered: you CAN pass a null as argument to the JDialog Constructor instead of a parent frame, cant you? (Or pass the main frame of you app, you will have a reference on it, won't you?)
Chantal
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's also the following method in SwingUtilities...


public static Window windowForComponent(Component aComponent)


Though you may have other problems if Component.getParent() returns null...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!