• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Make buttons in JoptionPane

 
Jason Newman
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, how do you make buttons on the JOption Pane? I know how to do it with the frame, but I am trying to make custom buttons for this pane. Like for example: Print out: How may I help you?" Button one :I'd like to ship, Button two: Uhh... Nevermind.

Please help?
 
Kevin Workman
Ranch Hand
Posts: 151
 
Jason Newman
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have a custom button made: But now how do I make the options pane show it?

JOptionPane panel = new JOptionPane();

JButton ship = new JButton("Ship a box");

panel.showMessageDialog(null, "Welcome to the Post Office, how may I help you?", "Welcome!",panel.);

It should say panel. something to show to button 'ship'
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Newman wrote:


I have a custom button made: But now how do I make the options pane show it?


Read this: http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the "Creating and Showing Simple Dialogs" section, sub section "showOptionDialog".
 
Jason Newman
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. It runs, which makes me happy. So, one more question: How do I assign these buttons values? As in if one button is clicked, then you selected choice one, which therein goes to... Ect. Help?
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you download the demo code and test it?

What part of the working example from the tutorial do you not understand?
 
Jason Newman
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The part where it tells you how to assign int variables for the buttons. As in "Blarg" is clicked then you have selected the value of '1' so then you go ----> here. Or is "blah" is click then go ------>here.

Are you getting my issue?
 
Jason Newman
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed it.

/thread
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic