Reputation: 113
I'm making a java proyect using eclipse and the windowbuilder plugin. After finishing the logic I've created an Application Window and execute the project, everything is fine. But now i want to modify the window, so i change the title for example. In the visual view, i can see these changes, but when i execute the application, there are no changes, it's always the same window. This is the code:
public class Application {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Application window = new Application();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Application() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("My Application");
}
}
I've just added one line so I don't know what could be wrong. I also want to know if this is the best way to make a gui application (using Application Window) or if there are better ways.
EDIT: I add some images to show which is the problem
Window when i execute:
Window in windowbuilder:
Upvotes: 0
Views: 864
Reputation:
I think that you should delete your swing and install it again. Because any solution is not working and there is no other reason not to. Just try to reinstall swing.
Upvotes: 0
Reputation: 321
You can set title using two ways:
1.Set title using JFrame setTitle() method : frame.setTitle("My Application");
2.Set title using JFrame(String Title) constructor: frame = new JFrame("My Application");
According to my opinion both ways work to set title but still if you are struggling with first option, you can try second option. May be this code works for you.
private void initialize() {
frame = new JFrame("My Application");
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Upvotes: 1
Reputation:
Please try this:
try {
Application window = new Application();
window.frame.setVisible(true);
window.frame.setTitle("My Application");
} catch (Exception e) {
e.printStackTrace();
And let me know the result.
Edit: remove setTitle() from initialize method.
Edit: If you are beginner you can try JavaFX. It is also simple as Java Swing but has some more potential, better design options and stuff. Its something I have tryed with when I was started Java learning.
Upvotes: 0
Reputation: 151
After setting changes, go frame.dispose()
and after that You can
frame.repaint();
frame.revalidate();
Upvotes: 0