0

I'm working on my first GUI in Java in Eclipse Neon. I created a content pane and gave it some code to print something out when a button is pressed. The problem is that I can't run the program. Eclipse won't display the run button. The only button that shows is the "External Tools" button. Is there something I'm missing in the code that's the problem or is it something else?

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.JScrollBar;
import java.awt.Color;

import javax.swing.JButton;
import javax.swing.border.MatteBorder;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

@SuppressWarnings("serial")
public class Test extends JFrame {

private JPanel contentPane;
private JLabel label;
private JTextField textField;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Test frame = new Test();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public Test() {
    super("Test GUI");
    setBackground(Color.GREEN);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 593, 458);
    contentPane = new JPanel();
    contentPane.setBackground(new Color(240, 248, 255));
    contentPane.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JTextArea textArea = new JTextArea();
    textArea.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
    textArea.setBounds(10, 11, 355, 366);
    contentPane.add(textArea);

    JScrollBar scrollBar = new JScrollBar();
    scrollBar.setBounds(371, 11, 17, 366);
    contentPane.add(scrollBar);

    @SuppressWarnings("rawtypes")
    JList list = new JList();
    list.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
    list.setBounds(398, 44, 139, 333);
    contentPane.add(list);

    JScrollBar scrollBar_1 = new JScrollBar();
    scrollBar_1.setBounds(543, 48, 17, 329);
    contentPane.add(scrollBar_1);

    JButton button = new JButton("Log Out");
    button.setBounds(438, 11, 71, 23);
    contentPane.add(button);

    textField = new JTextField();
    textField.setColumns(10);
    textField.setBounds(10, 384, 460, 20);
    contentPane.add(textField);

    JButton button_1 = new JButton("Send");
    button_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            label.setText("Yeah, It Works!!!");
            textArea.add(label);
        }
    });
    button_1.setBounds(488, 383, 57, 23);
    contentPane.add(button_1);
}
}

Here is a link to the screenshot of eclipse. Notice there is no run button in the menu options: Screenshot of Eclipse Neon

Thanks in advance

zedzorander
  • 47
  • 1
  • 8
  • Have you set `Test` as the main class [for example](https://stackoverflow.com/questions/17397440/how-to-setup-main-class-in-run-configurations-in-eclipse)? Also avoid placing classes in the "default" package, that can cause other issues – MadProgrammer May 24 '17 at 01:53
  • I created it by right clicking on src ->new->other and then in the swing designer folder in window builder I chose JFrame. So I don't think I set it as the main class. I'll try that. – zedzorander May 24 '17 at 02:06
  • Ok. I set it as the main class and it let me run it. There are bunch of errors but that's ok, I can figure those out. Thanks for the help. – zedzorander May 24 '17 at 02:18
  • I use eclipse neon also, you can just `Right Click > Run As > Java Application` –  May 24 '17 at 03:37

0 Answers0