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

Is it possible to use Textbox and Combobox at the same time with JOptionPane?  RSS feed

 
David Martínez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there! This is my first post here, I've been learning java for about 2 months now, and I need your help with some questions!

As the title says, I have this homework where I need to make a user input where the user will write his email, the teacher wants it to be like this:


Is it possible to do it with JOptionPane? Or is it more complex than that ?
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you can. Have a look at the APIs
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add any component to a JOptionPane.

So yes you can add a JPanel containing those two components.
 
David Martínez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't edit my previous post

I forgot this, this is the real main class!

 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Martínez wrote:I can't edit my previous post . . .
Unfortunately, I can make you edit the previous post. Sorry about this, but the lines were so long I am going to have to ask you to change them. There are more details in the old Sun style guide and our Ranch FAQ. Sorry about that.

And welcome to the Ranch
 
Fred Kleinschmidt
Bartender
Posts: 507
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your RegistroEstudiante.inicio() method creates a new Correos instaqnce named "Correos".

First, it is a bad idea to have an instance variable whose name begins with a capital letter, especially if that makes the instance variable name identical to the name of the class.

Second, why are you creating a new Correos there? Your RegistroEstudiante instance is already a Correos.
So now you have two Correos instances, each with its own separate correoConcatenado variable.
Your actionPerformed() method is setting one of those, and your Correos.getCorreoConcatenado() method is returning the value of the other one, which has never been reset.
 
Brian Cole
Author
Ranch Hand
Posts: 935
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:You can add any component to a JOptionPane.

So yes you can add a JPanel containing those two components.


JOptionPane's message parameter is declared to be of type Object. So, yes, you can pass a JPanel and it will work, but you don't actually need to use a JPanel.

You can pass a simple array for the message (for example, an array of length 5 that contains a String, a JTextField, another String, a JComboBox, and one more String). This is described in the JavaDocs for JOptionPane, not in the method descriptions but in the text at the top of the javadoc page.
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can pass a simple array for the message... 


Yes, but the components will be vertically aligned.

If you want full control over the layout of the components then you would use a JPanel.

The approach you use depends on the requirement.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!