aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Cannot take populate JTextfield Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Cannot take populate JTextfield" Watch "Cannot take populate JTextfield" New topic
Author

Cannot take populate JTextfield

Rohit Kedia
Ranch Hand

Joined: Apr 24, 2010
Posts: 79
Hi,
I am a novice in Swing so I need help from you... I have a situation here :
In one JFrame I have multiple JPanels.
In each JPanel I have 1 JLabel , 1 JTextfield & 1 JButton .
Now clicking on the JButton a small JFrame opens up where the user can search for a particular user.
Now if he wants to select the user , he has to select the JRadioButton against it.

Now I want here is that when he clicks the Add button then that small JFrame should be closed and the selected User ID should be populated in the respective JtextField of the JPanel.

Can anyone help me in this situation.

Note I am able to close the small JFrame by invoking JFrame.dispose(); but how should I populate the JTextField.
The whole concept highlights about selecting a User from a Popup and adding it to the Parent JTextField.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

How about using JOptionPane? The "message" parameter can be anything, including entire JPanels with contents.
However, maybe a single selection JList (inside a JScrollPane) is a better option for selecting the user.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rohit Kedia
Ranch Hand

Joined: Apr 24, 2010
Posts: 79
Hi Rob Sir,
But in my small JFrame (It is a Popup )
I have 3 JTextFields(User ID , First Name & Last Name) as Search Parameter and a Search JButton.
Now after providing any of the 3 values when I click on the Search Button.
I am populating a JTable with 3 columns a) User ID (JRadioButton), b) User Name & c) Email Address.

And two Jbutton "ADD"(which will add the User in the Main JFrame TextField) & "Exit" which will only close the Popup.

So it this Possible in the JOptionPane ???
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2172
    
    7
You can show any Swing compnent using the showInputDialog(...) method. So yes you can add a JPanel containing the components you describe.
Rohit Kedia
Ranch Hand

Joined: Apr 24, 2010
Posts: 79




any help
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

The message, searchView in this case, cannot be a JFrame or JDialog.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
"...adding a window to a container"

so, what is 'searchView'
Rohit Kedia
Ranch Hand

Joined: Apr 24, 2010
Posts: 79
Hi,
That issue is resolved but the now the Whole Panel is not displaying all the Components in the JOptionPane
Rohit Kedia
Ranch Hand

Joined: Apr 24, 2010
Posts: 79
Rob Prime wrote:The message, searchView in this case, cannot be a JFrame or JDialog.


Yes actually the I was adding a JFrame but now I have chaged it to a JPanel within that there is my Main Panel which holds all the Components but the Problem is that it is not showing
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Are you trying to show the content of an existing frame? You should create a new JPanel that isn't shown anywhere else yet; the JOptionPane will create a JDialog that will house the JPanel.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Cannot take populate JTextfield