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