Need help with dialog option buttons

I am trying to make a program with a menu displaying several buttons that the user can select. I've been following the "How to Make Dialogs" tutorial but the window becomes extremely long when the buttons are displayed horizontally in the same row and there doesn't seem to be a way to make the option buttons display vertically in a column rather than horizontally in a row with JOptionPane. Is there another way to do it?
URL for tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html

Here's a simple example of what I mean. If you go my route, you'll understand how to do this. If on the otherhand you do rgjonathan's suggestion, you'll lose out and be forced into whatever pigeon-hole that NetBeans forces you into:
DialogExample.java: a class that creates a JPanel with vertically stacked JButtons. This JPanel can easily be placed within a JDialog.
import java.awt.GridLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
* creates a mainPanel that can be used in a JDialog
* @author Pete
class DialogExample
    private JPanel mainPanel = new JPanel();
    private String buttonStrings[] =
        "Fubar", "Snafu", "Bohica", "Subar"
    private String actionCommand = "";
    public DialogExample()
        mainPanel.setLayout(new GridLayout(0, 1, 10, 10));
        mainPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
        for (int i = 0; i < buttonStrings.length; i++)
            JButton btn = new JButton(buttonStrings);
mainPanel.add(btn);
btn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
actionCommand = e.getActionCommand(); // set actionCommand field
Window window = (Window)mainPanel.getTopLevelAncestor();
window.dispose(); // close this window
* @return a JPanel that can be used in a JDialog
public JPanel getMainPanel()
return mainPanel;
* @return String: actionCommand corresponding to the button pushed
public String getActionCommand()
return actionCommand;
}DialogTest.java:  creates a trivial JFrame with a JButton that when pressed creates a JDialog with the JPanel from the class above.  Gets the name of the button pressed in the dialog and prints to screen.import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class DialogTest
private static void createAndShowGUI()
final JFrame frame = new JFrame("Test");
final DialogExample dialogEg = new DialogExample();
JButton openDialog = new JButton("Open Dialog");
openDialog.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent arg0)
boolean modal = true; //modal dialog or not?
JDialog dialog = new JDialog(frame, "Dialog", modal); // construct dialog
dialog.getContentPane().add(dialogEg.getMainPanel());
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true); // show it
System.out.println(dialogEg.getActionCommand()); // find out which button pressed
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(openDialog);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main(String[] args)
javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
createAndShowGUI();

Similar Messages

  • Need help with Flash CS4 buttons/can't get buttons to control anything

    Hello,
    I need help with Flash CS4. I am making a banner with an animation (Image change into movie clip "3D Spiral") and added buttons but I cannot get the buttons to control the animation. Please help I am frustrated! If someone could help I would be most appreciated.

    Thank you.
    Regards,
    Michael J. Sheehan  allelois
    Date: Mon, 17 Aug 2009 18:48:09 -0600
    From: [email protected]
    To: [email protected]
    Subject: Need help with Flash CS4 buttons/can't get buttons to control anything
    Hi there
    I'm not sure how you wound up where you did. But you wound up in the Adobe Captivate forums. Please stand by as I move your thread to the Flash forums.
    Cheers... Rick
    >

  • Need help with Cluster of Buttons displaying a message to which button is being pressed.

    Create a VI with a cluster of six buttons labeled Option1…Option6. When executing, the VI should wait for the user to press one of the buttons. When a button is pressed, use the Display Message To User Express VI to indicate which option was selected. Repeat this process until the user presses the Stop button. The parameters of the problem needs me to use a while loop, case structure, a shift register and search 1d array. I'm just having trouble setting up my case structures and how to get the search 1d array to work with the cluster to find which button was pressed. I've attached a picture of my VI and also a VI I made without the cluster that does what I want the Cluster VI to do which is to recognize the button being pressed and bring up a prompt.
    Solved!
    Go to Solution.
    Attachments:
    Button Pressed.jpg ‏127 KB
    Buttons Pressed No Cluster.jpg ‏189 KB

    Okay so i moved the cluster into the while loop and wired a boolean true constant to the element of the search 1d array and now I can at least get the prompt for button 1 to display, but when I press the other buttons which I have set up the same way as button 1 I get no prompts so how can I get it to recognize the other buttons. Am I implementing the shift register incorrectly? 
    Attachments:
    Button Pressed 2.jpg ‏115 KB

  • Need help with audio on button ASAP THANKS!

    Hi,
    Using CS3 I added via properties audio to the "over" part of a gold button.  The audio I added is 4Mb in size which I had imported to the library.  When I selected "over" on the button and then using properties assigned the audio file .... the wave form appeared ... but not under "over" but over, down and hit.  Thus when I publish what is happening is the page loads fine ... the audio begins to play on roll over as wanted ...
    HERES THE GLITCH:  if you accidently roll over again a new audio begins to play out of sync with the first one ... basically you get the row, row row your boat effect where each roll over audio is delayed.
    MY FAILED SOLUTION:  I tried to move the audio file and assign it via properties under hit. Thus have to have someone click on the sound.  Yet the same outcome happend where the wave form appeared not just under hit but it showed on over, down and hit. The same thing happened when I tried assigning to "down".
    MY QUESTIONS:
    Is this caused by the sound file being too big?  I tried a small audio beed and it would assign directly under the part I assigned but not with the bigger 4MB audio file.
    If it is the size of the sound file, can I link the button to an external audio file. If so, what code would I use if I am using Action Script 2.0. I am very new at action script.
    If it is not the size, could some one please tell me how to fix this glitch.  I would be satisfied with the button working on either over or hit.  If you wish to see what the button is doing, you can see it online at www.signaturehill.com.
    THANKS.

    Hi Erika,
    That might just be what I need ... but I am confused as to where do put the action code.  Can you help me with the following questions:
    1. Did you put it inside the button via actionscript or did you select the button just and ad it there ...  or somewhere else? Since I have several buttons doing the same thing on different pages, I am not sure where to put it.
    2. What was the exact code you used  ie  on (release)  {....   StopAllSounds(); }  .... did you even use "release" or some other mouse event.
    Please include the action script code I might try since I am very new to scripting. THANK YOU>

  • Need help with Motion Tracking-button in After Effects CS6

    Hello I just bought After Effects cs6 and wanted to try ''motion tracking'' but I just can't push the motion tracking button. Is there anyone who can help me with that problem?
    Responses are highly appreciated!

    In order for the motion tracking buttons to become highlighted, you first need to select the clip you'd like to track in the timeline:

  • New to Adobe Forms and need help with Submit Email button

    I am new to Adobe Forms in Windows.  I created a form with a submit email button.  When users try to click the button, the message is operation cannot be completed.  My test user has Adobe Reader 9 installed.  I'm at a loss as to how to resolve the issue.  Please assist.  TIA!

    Three different aspects
    1. Set the form up to submit the data (XML or FDF), not the full PDF. You can import the data to the PDF on your end.
    2. You can turn on Extended Reader Rights, but then limit the use/users to 500 by the EULA. The applicability of this option depends on your intended application. In a small office, it would be fine. For general web use you would likely exceed the limit and be in violation of the EULA.
    3. There may be an e-mail problem, one reason that e-mail is not recommended for form submission (even if the manual discusses it). Again, in a controlled environment like an office it will probably work fine, but in a web setup it is best to use a web script. There are 2 problems with e-mail that both depend on the client system (YOU have no control, but will be blamed in any case). First, the client machine has to be set up as an active MAPI client. Many folks do not have this on. Second, some e-mail clients treat PDFs like text and the result is a corrupt e-mail submission, even if it makes to you.
    If you have the possibility of web submission, do it. I suggest only having the form data submitted and not the form.

  • Need help with tool bar button to clear 10 fields on form

    I have 167 forms with 138 fields, I need to blank out or clear just 10 of them or so, can I create a butotn or script that is outside each document so I can open each one, andc lick this button?
    I don't want to add a button to all 167 pdf files. Or better yet script to open them all and blanks out the fields, evey form is the same so the field names are the same.

    This would be easy to do as a batch process (aka Action). The following JavaScript will do it:
    // Create an array with the list of fields to reset
    var fa = ["text1", "text2", "text32", "text4", "text5", "text6", "text7", "text8", "text9", "text10"];
    // Reset the fields
    resetForm(fa);
    This will set each of the named fields to its default value. If the default value might be different than blank, replace the last line with:
    for (var i = 0; i < fa.length; i++) {
        getField(fa[i]).value = "";
    Replace "text1"..."text10" in the first line with the actual names of the fields you want to clear.

  • Need help with Language option!

    Can I choose a template or copy an existing form, and translate it into another language?  How do I do this?  I can't find any help in the FAQs....

    Yes, the templates are completely editable (note in the bottom left corner of the template tab there is a drop down that allows you to select other languages for the templates).
    You can go to the Options tab -> Language section to change the language of the form (this changes the error messages, submit button, etc).
    Randy

  • Need Help with universal option??

    My daughter need to run an application in rosetta so I found where I am supposed to go to app, get info and check the box open in rosetta well the General folder says kind:Folder instead of the universal and where the check box for start in rosetta is it says shared folder?
    Any help greatly appreciated! This is for her Macbook with leapord.

    You can't "run" a folder in Rosetta. You can only run applications. Some applications are "stand-alone", some are inside folders with other related files they need.
    Open the folder and find the icon for the actual application. Click once on the actual application icon (to select it) and then Control or right-click or Cmd + I to "Get Info" and the "Info" window will open.
    You will see the ""Open Using Rosetta" box just underneath the colored boxes near the middle of the window.
    After checking that box you just close the window.
    Leopard will know to use Rosetta to run that particular program.

  • I need help with setting my button to link to my website! URGENT HELP!!!!

    Hello everyone. Lately, I've been trying to link a button to my site with Action Script 3, however, whenever I try to load my movie, I keep getting an error! The error says: Scene 1, Layer 'Button', Frame 1, Line 5 1071: Syntax error: expected a definition keyword (such as function) after attribute fuction, not pes.
    This is what I wrote...
    stop();
    peshp_btn.addEventListener (MouseEvent.CLICK, pes);
    fuction pes(e:MouseEvent):void{
    var pesLink:URLRequest = new URLRequest("http://www.penguinentertainmentstudios.com");
    navigateToURL(pesLink,"_blank");
    PLEASE HELP ME I IVE BEEN TRYING FOR ALMOST 2 HOURS NOW!!!!!

    Use the following:
    peshp_btn.addEventListener(MouseEvent.CLICK, pes);
    function pes(event: MouseEvent) {
    var pesLink:URLRequest = new URLRequest("http://www.penguinentertainmentstudios.com");
    navigateToURL(pesLink, "_blank");

  • Needing help with a simple button

    Hey everyone
    I'm wanting to put a link on my flash banner to an external website. I have followed the example here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/2/help.html?content=00000 394.html
    but it still doesnt seem to work as when I click the button I get the Adobe Flash Player Security box seen in the screenshot I have attached. I have click settings and added the website as a trusted source but the link still doesnt take me to the website. I'm using actionscript 2 on request.
    Thanks in advance

    You should test using a browser.  I rarely run into that issue but I think you need to specify the location of the local swf file instead of the web url.

  • Need help with sync option

    I cannot get my ipod to sync new songs. it keeps giving me an error, please help

    we need more information. what is the error? how are you connecting? USB or Firewire?

  • Need help with reviewer CS4

    I am usung the Captivate reviewer to distribute draft modules.
    The problem I am havving is the .LOCK file - when someone goes to review the module, they have to specify the location of a temp file. (the .lock file). When they have finished that module, then they have to either specify a new location for the next module, ot manually delete the lock file.
    Is there a way to disable the comments logging feature, or have the lock file automatically deleted?
    Thanks
    Terry

    Thank you.
    Regards,
    Michael J. Sheehan  allelois
    Date: Mon, 17 Aug 2009 18:48:09 -0600
    From: [email protected]
    To: [email protected]
    Subject: Need help with Flash CS4 buttons/can't get buttons to control anything
    Hi there
    I'm not sure how you wound up where you did. But you wound up in the Adobe Captivate forums. Please stand by as I move your thread to the Flash forums.
    Cheers... Rick
    >

  • Need help with AS8 configuration

    Our present situation is like this:
    AS7 with single domain and multiple server instances
    instance A running on port xxx containing app1
    instance B running on port yyy containing app2
    instance C running on port zzz containing app3
    Now, when I move to AS8.1 PE, I dont see the option to create a server instance inside a domain. I need to create 3 domains in order to accomplish the same task as above. Not only that, now I need to login to 3 different admin servers to manage the 3 apps on 3 ports
    I need help with some options I can use
    thanks

    I'm not sure but i think that on 8.1 pe you can have only one server instance by default...
    But you can olso try by command line tool asadminin [installdir soas]/binuse:
    asadmin --help for a list of commands available.
    In the list should be create-instance to create a stand alone instance.
    Hi
    Stefano

  • I need help with a PDF file that is an image, the "Read Out Loud' option does not work, please help!

    I need help with a PDF file that is an image, the "Read Out Loud' option does not work, please help!

    You mean an image such as a scanned document?
    If that is the case, the file doesn't contain any text for Reader Out Loud to read. In order to fix that, you would need an application such as Adobe Acrobat that does Optical Character Recognition to convert the images to actual text.
    You can also try to export the file as a Word document or something else using ExportPDF which I believe offers OCR and is cheaper than Acrobat.

Maybe you are looking for

  • Problem with image transparency in Director

    We want to use some Photoshop images with some transparency and gradients (ie foreground color to transparent background) in a project where the image will be placed over various other background images (the background images will show through the tr

  • HT201317 Unsure about iCloud

    If I turn off my iCloud in my iPad for my phone, will that delete the iCloud I have on my phone? (Or vise versa) I want to have iCloud in both my iPad and my phone, but I don't want my information synching with one another.

  • None of my passwords are working on my macbook pro

    I booted up my computer for the first time this afternoon and one of the passwords I use will not be accepted for the logins I use it for.  This includes whhen I am asked to update my software, install new software, boot up in safemode, and even auth

  • Need for Upgrade as Opposed to New Installation

    What is the need to upgrade from 9i to 10g or 10g to 11g or 9i to 11g? If your database is relatively small, can an Oracle Export, uninstall database and install upgraded version desired be performed in place of an upgrade? What are the issues involv

  • N97 Not powering up.......

    Hi guys i was having a few probs with my n97 so i tried re-updating the software via ovi suite then it came up with an error so i disconnected the usb and remove the battery once when i put it all back in the phone does not power up i can feel the in