Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    java GUI problem

    I'm new to programming in GUI, and the problem I having is that I have a textbox, and a OptionPane. But everything I have tried, the OptionPane always comes first, and I have know idea why it's happening

    code: import java.awt.*;
    import javax.swing.*;

    public class test4 extends JFrame {

    private JTextArea txtBOX;
    public test4(){
    setLayout(new FlowLayout());

    txtBOX = new JTextArea("pick 1, 2, or 3);
    add(txtBOX);

    String co = JOptionPane.showInputDialog("1, 2 or 3?");
    }

    public static void main (String args[]) {
    test4 GUI = new test4 ();
    GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GUI.setVisible (true);
    GUI.setSize(290,300);
    }
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This is the incorrect forum; moving to Java forum.
    I'm not certain I understand your question. A JOptionPane is a distinct component from the JTextArea, and by invoking the showInputDialog it should create a popup input for the client to input data. This will show up prior to the rest of the GUI since you haven't set the visibility of it yet. You should be able to invoke the input from JOptionDialog after you finish the painting for the frame.
    If I understand what you are trying to do here though, there's no reason to concern yourself with the JTextArea at all, instead you can simply provide a selection input on the JOptionPane itself:
    PHP Code:
    Object[] items = {123};
    Integer input Integer.parseInt(
        
    JOptionPane.showInputDialog(
            
    this,
            
    "Pick one of the following:",
            
    "Choose your input",
            
    null,
            
    items,
            
    1
        
    )
    ); 
    Untested, but you should end up with an Integer of the selected item from the input.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •