Win a copy of Classic Computer Science Problems in Swift this week in the iOS 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

 
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 ?
 
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
 
Rancher
Posts: 2892
17
  • 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!

 
Marshal
Posts: 58830
179
  • 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
 
Bartender
Posts: 608
9
  • 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.
 
Author
Ranch Hand
Posts: 959
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
Rancher
Posts: 2892
17
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!