Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: JDialog from JFrame button (GUI)

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JDialog from JFrame button (GUI)

    Hi

    So I aim to make a GUI with 9 buttons, each one opening up a new window (JDialog) with input fields/tickboxes etc...

    My code so far opens up a new Jdialog but does not display my added components (JTextFields) I cannot see why. My JDialog is just blank.
    Any ideas?
    public void actionPerformed(ActionEvent e) {
    		Object s = e.getSource();
    		if (s == addHose) {
    			// JDIalog
    			JTextArea addOwner, addNumberOfSections, addBore, addUsage, addLength;
    			JRadioButton addHasTapAttachment, addHasJet, addIsOnDisplay;
    			// buttons
    			JButton btnOK, btnCancel;
    			// variables representing user input
    			String owner, numberOfSections, bore, usage, length;
    			AccessibleContext hasTapAttachment;
    			AccessibleContext hasJet;
    			AccessibleContext isOnDisplay;
    			JPanel main, addHosePanel;
     
     
    			JDialog addHoseD = new JDialog();
     
    			addHoseD.setLayout(new FlowLayout());
     
    			addOwner = new JTextArea();
    			addHoseD.add(addOwner);
    			owner = addOwner.getText();
     
    			addNumberOfSections = new JTextArea();
    			addHoseD.add(addNumberOfSections);
    			numberOfSections = addNumberOfSections.getText();
     
    			addBore = new JTextArea();
    			addHoseD.add(addBore);
    			bore = addBore.getText();
     
    			addUsage = new JTextArea();
    			addHoseD.add(addUsage);
    			usage = addUsage.getText();
     
    			addLength = new JTextArea();
    			addHoseD.add(addLength);
    			length = addLength.getText();
     
    			addHoseD.setTitle("Add Hose");
    			addHoseD.setModal(true);
    			addHoseD.setSize(250, 300);
    			addHoseD.setVisible(true);


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: JDialog from JFrame button (GUI)

    To see what is happening change this line:
    addNumberOfSections = new JTextArea("nbr of Sect");

    or add this line:

    addHoseD.add(new JButton("Press me")); //<<<<<<
    Last edited by Norm; April 5th, 2012 at 07:09 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JDialog from JFrame button (GUI)

    Right, ok.

    I've added that code and it looks like this:



    The text areas will just be attributes to my object (the hose) that the user will fill in.

Similar Threads

  1. JDialog Failing to Render...
    By snowguy13 in forum AWT / Java Swing
    Replies: 2
    Last Post: April 7th, 2012, 11:55 AM
  2. [SOLVED] sending a parameter to a new JDialog
    By luisp88 in forum AWT / Java Swing
    Replies: 4
    Last Post: October 5th, 2011, 09:31 AM
  3. Open JFrame Form With Button
    By cardamis in forum AWT / Java Swing
    Replies: 2
    Last Post: April 12th, 2011, 03:18 AM
  4. [SOLVED] Click button to open JDialog
    By susieferrari in forum Java Theory & Questions
    Replies: 6
    Last Post: March 30th, 2011, 09:24 AM
  5. close JDialog on button click
    By Christophe in forum AWT / Java Swing
    Replies: 4
    Last Post: April 4th, 2010, 11:04 PM