View Full Version : Swing GUI not loading in Java app..
chacelp
February 20th, 2007, 12:57 AM
This might be a stupid question but I am so good at asking them! I am creating a Java application, needless to say it runs on tabs, and I have been using the Swing package to add my textboxes, buttons, etc. Everything looks fine and dandy in NetBeans but once I compile/build/run the app it shows up as a native Java window and buttons, textboxes, respectfully. Am I missing something that would allow what I see in the IDE to be opened when the .jar is run, in terms of the GUI?
kirupa
February 20th, 2007, 05:13 PM
If I read your question correctly, you aren't seeing the Swing-ish layout that you see inside NetBeans?
Try this line of code to override any default settings and display the metallic look:
UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName());
chacelp
February 20th, 2007, 09:36 PM
I did some research on your suggestion Kirupa and after some importation and a few trys I was able to get my app to compile and run without problems, however the 'metal' L&F didn't show. :a:
I have been getting this error both with and without the UIManager setting the L&F:
Note: C:\Documents and Settings\hp\Desktop\Senior Project\Changes\ChaceBuild\src\javaapplication3\Ne wJFrame.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Any suggestions?
chacelp
February 21st, 2007, 01:02 AM
Well thanks to Kirupa I fixed the L&F of my project. Turns out I was trying to add the UIManager.setLookAndFeel to just the JFrame which I wanted to change the GUI on.
Which works when you run an individual java file. However, when run through a package or instantiated through another class, unless the main class and the swing frame in which you wish to display with L&F have the code, it will default to Java's native metal GUI. The following code worked for me to change the LookAndFeel to the host computers native settings.
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
}
catch (UnsupportedLookAndFeelException e) {
// handle
}
catch (ClassNotFoundException e) {
// handle
}
catch (InstantiationException e) {
// handle
}
catch (IllegalAccessException e) {
// handle
}
new NewJFrame().setVisible(true);
}
Thanks for the help Kirupa!
kirupa
February 21st, 2007, 01:20 AM
I've made that mistake before....many times! :beam:
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.