t0r3 Posted April 24, 2019 Share Posted April 24, 2019 Hey I am trying to learn how to make a GUI from expLvl's Tutorial I can't get the JButton to show when i run the main method, why is this? I am fairly new to java, and am in process of learning it. So sry, if it is apparent haha. Any help/tips appreciated Thanks! package gui; import data.TreeInfo; import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; public class GUIDialog extends JDialog { private final JDialog mainDialog; private final JPanel mainPanel; private final JPanel selectTreeTypePanel; private final JLabel treeTypeLabel; private final JButton startButton; private final JComboBox<TreeInfo> treeTypeComboBox; public GUIDialog() { mainDialog = new JDialog(); mainDialog.setTitle("Tasks Woodcutter"); mainDialog.setModal(true); mainDialog.setModalityType(JDialog.ModalityType.APPLICATION_MODAL); mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS)); mainPanel.setBorder(new EmptyBorder(20, 20, 20, 20)); selectTreeTypePanel = new JPanel(); selectTreeTypePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); treeTypeLabel = new JLabel("Select Tree : "); selectTreeTypePanel.add(treeTypeLabel); treeTypeComboBox = new JComboBox<>(TreeInfo.values()); selectTreeTypePanel.add(treeTypeComboBox); mainPanel.add(selectTreeTypePanel); startButton = new JButton("Start"); startButton.addActionListener(e -> { started = true; close(); }); mainPanel.add(startButton); mainDialog.getContentPane().add(mainPanel); mainDialog.getContentPane().add(selectTreeTypePanel); mainDialog.pack(); mainDialog.setLocationRelativeTo(null); } public void open() { mainDialog.setVisible(true); } public void close() { mainDialog.setVisible(false); mainDialog.dispose(); } public static void main(String... args) { new GUIDialog().open(); } } Quote Link to comment Share on other sites More sharing options...