• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes you can. Have a look at the APIs
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't edit my previous post

I forgot this, this is the real main class!

 
Marshal
Posts: 79178
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 732
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic