Although I used Swing before I never used a GUI constructor, and I had problems accessing the components, which I reset to my panel from my source code.
I created a new project and decided to create a GUI form. Then I created the main method using the "generate" parameter, and now I have this code in the file "helloWorld.java".
public class helloWorld { private JPanel myForm; private JLabel text; public static void main(String[] args) { JFrame frame = new JFrame("helloWorld"); frame.setContentPane(new helloWorld().myForm); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(800, 600)); frame.pack(); frame.setVisible(true); } }
Then I added JLabel in the constructor with the name of the title field, which added an attribute to the head of my helloWorld class. Now I want to set the text by the name of the field after starting the program.
If I create an instance of JLabel with a new line as an argument and add it to my JFrame, then the program will fail with an exceptional exception.
If I create a JLabel with no arguments and call setText on it and then redraw it on a JFrame, nothing happens.
I can guess some problem in one line: how do you access the components that I created using the GUI designer?
java user-interface intellij-idea swing
Ash
source share