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 4 of 4

Thread: JDialogs

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default JDialogs

    I am a complete newbie in making GUI in Java Swing and Java in general. I am use to using Qt, so any harsh comments and feedback will be taken lightly, so don't worry about my naive questions. It took me a while to make a Dialog with just using JPanel and JFrame, but my problem is when I execute the program two dialogs pop-up. One with the right display and one that is completely blank and small.

    If someone can tell me what I am doing wrong I would greatly appreciate it.

    Here is the code. OH ALSO comment on how to properly post code as well.

    Thanks

    package com.familydatabasetest.domain;
     
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
     
     
     
    public class MainForm extends JDialog{
     
        private final JTable nameTable;
        private JScrollPane nameScroll;
        private final JTable infoTable;
        private JScrollPane infoScroll;
     
        private JPanel mainPanel;
        private JPanel buttonPanel;
     
        private JButton addNameButton;
        private JButton deleteNameButton;
        private JButton editButton;
     
        public MainForm(){
     
            final JFrame frame = new JFrame("Family Database");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(500, 500);
     
            nameTable = new JTable();
            nameTable.setPreferredScrollableViewportSize(new Dimension(100, 200));
            nameTable.setFillsViewportHeight(true);
            nameScroll = new JScrollPane(nameTable);
            infoTable = new JTable();
            infoTable.setPreferredScrollableViewportSize(new Dimension(100, 200));
            infoTable.setFillsViewportHeight(true);
            infoScroll = new JScrollPane(infoTable);
     
            addNameButton = new JButton("Add Name");
            addNameButton.setPreferredSize(new Dimension(50, 5));
            addNameButton.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    NameForm nameform = new NameForm();
                    nameform.show();
                }
            });
            deleteNameButton = new JButton("Delete Name");
            deleteNameButton.setPreferredSize(new Dimension(50, 5));
            editButton = new JButton("Edit");
            editButton.setPreferredSize(new Dimension(50, 5));
     
            mainPanel = new JPanel();
            mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
            buttonPanel = new JPanel(new GridLayout(1, 3));
     
            buttonPanel.add(addNameButton);
            buttonPanel.add(deleteNameButton);
            buttonPanel.add(editButton);
     
            mainPanel.add(nameScroll);
            mainPanel.add(infoScroll);
            mainPanel.add(buttonPanel);
     
            frame.setContentPane(mainPanel);
            frame.setVisible(true);
     
        }
    }
     
    //Here is the main
    package familydatabasetest;
     
    import com.familydatabasetest.domain.MainForm;
     
     
    public class FamilyDatabaseTest {
     
     
        public static void main(String[] args) {
     
     
            MainForm mainform = new MainForm();
            mainform.show();
     
     
        }   
    }

    //Keep in mind I am use to using C++/QT
    //Thanks


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

    Default Re: JDialogs

    Here's one:
    public class MainForm extends JDialog{
    ...
    mainform.show();

    and here's another:
    final JFrame frame = new JFrame("Family Database");
    ...
    frame.setVisible(true);
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    LaTJ (October 24th, 2013)

  4. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JDialogs

    Sorry for the late delay I had trouble with my screen. Anyways, what's wrong with pubic class MainForm extends JDialog. I got that from a tutorial. Do I have to call its constructor??

    Please explain with more detail so.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JDialogs

    I was answering this concern:
    my problem is when I execute the program two dialogs pop-up.
    by showing where the 2 windows come from.
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    LaTJ (October 25th, 2013)