How can i set defaultlookandfeel to window for Jframe - java

I made a simple Jframe with its child components in netbeans, when i run the application it shows it in NIMBUZZ lookandfeel as shown below:-
But I want it to be always shown in WINDOWS lookandfeel as shown below :-
How am I suppose to do that??

Before creating your first window call this code:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
note that this will work as expected only under windows where this is the system LAF

You maybe looking for setWindowDecorationStyle(), although some L&Fs may not support the feature. A complete example is cited here.

Related

Changing LaF based on OS

Im building a GUI in Netbeans, it looks good in the designer but when I run the program it looks pretty rubbish. Im using a Mac and so I feel that it would look better using the Mac OS LAF but then when I run it on Windows, what will happen? Is a Windows system able to use the Mac LAF and vice-versa?
I dont usually mind the Ocean/Metal LAF but it looks better on Windows than it does on Mac, is there a way to set a theme as a fallback? Or to change depending on the system its running on?
The UIManager.setLookAndFeel(String className) Loads the LookAndFeel specified by the given class name:className, using the current thread's context class loader.
To set look and feel of your current system, make use of UIManager.getSystemLookAndFeelClassName(): Returns the name of the LookAndFeel class that implements the native system look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
put this code before you create instance of your application window: JFrame or any such Top-level Container.

Why in my Java application am I seeing "strange" scrollbars?

In my Java application I have a window which holds a JTextArea within a JScrollPane with scrollbars policies set to AS_NEEDED.
As I run my application I see that JTextArea this way:
Why am I seeing the scrollbars with that cutaway knob (which doesn't reflect a "standard" representation like this)?
The Layout for the frame is GridBagLayout, and I'm on Mac OS X 10.8.2, should that matter.
This is based on the Look and Feel your app is using, and the limitations of Java's integration with the native OS layout components. The one in your screenshot looks like Nimbus.
Swing applications always custom-render the look and feel, and don't do a very good job of using the native OS widgets everywhere. The result is that you get weird looks that might be consistent the OS only some of the time, or only with certain layout components.
Welcome to developing cross-platform desktop apps in Java. :(
To attempt to get the system look and feel when your application starts you can do this:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassname());
} catch (Exception e) {
// Handle exception
}
This will set the look and feel to that of the system regardless of what you run it on.
And as mentioned, the default look and feel for your application appears to be Nimbus and not OSX's Aqua, which again can be fixed with he above snippet and you could (should you care to) offer a UI option to the user to change the look and feel of the application to whatever they chose.
You are with Nimbus LookAndFeel
http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/nimbus.html

JFrame theme and appearance

I have a swing application. Below is a small screenshot.
OS: Win 7
What is irritating is the theme. I have tried several other screens but they all have such appearance. Eclipse and Netbeans for example have a much better UI. The FileChooser and Frame is general is much pleasing. How do I have such a theme.
Thanks.
Change the look and feel to the Windows one before creating anything UI-related in your program:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Looks like you are using the Metal Look and Feel. Try using some other look and feel that might interest you.
Refer http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html, for more information.
This will give you everything you want to know
http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
UIManager.getSystemLookAndFeelClassName() will give you the most appropriate for the OS it's running on
there is many look and feels packages like :
1)JTattoo
2)BlueLight
3)joxy
4)Nimrod
5)Oyoaha
6)TinyLaf
....etc
you have to read about previous types

Java look and feel for tray does not work

I use UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); to set a LAF and it works fine. But this time I also implemented a tray and it looks ugly - like Motif. How can I set LAF for the tray?
The class you're probably using for this is java.awt.SystemTray.
The tray uses AWT, not Swing. You cant set the look and feel of it.
I think there is a duplicate of this somewhere on here.

Java, Netbeans: How come the GUI looks different?

I'm a Java/Netbeans newbie learning how to make a GUI.
I was following this tutorial, and I noticed that the "finished" product (first picture in that link) doesn't look like the GUI built through the steps.
Why is that? I mean, when I click on the preview button, the GUI looks native (nice) as well. It's just when it's deployed that it looks all...mmm...bad. lol.
Is there a way to make the finished GUI looks native? Is it Netbeans settings or Java settings?
Note: I'm developing this on Windows.
Use the following code to force swing to select the "system" look and feel:
String laf = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(laf);
The default "Look and Feel" is metal-like, which is good and nice for cross-platform applications.
JDK has 4 built-in "look and feel" ('til now), which are:
com.sun.java.swing.plaf.gtk.GTKLookAndFeel
javax.swing.plaf.metal.MetalLookAndFeel
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
you can try any of these "look and feel"s in 1 line, example code:
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
NOTE: invoke/call this method of changing the "look and feel" before any GUI implementation, or it may throw some exception
This is referred to as the "look and feel". You can use various look and feel either when launching your app or programaticaly. See this Sun tutorial for more info.

Categories