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
Related
I want to run my application in different platform and i want to use different look and feel for each platform. could you please guide how can approach this?
This is what i did.
in main java class i added static block and by adding below condition.
if(System.getProperty("os.name").startsWith("Windows")) //Added for linux
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
else
{
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
}
When I run my application in linux platform, it is not showing metal look and feel rather it's showing java default look and feel mainly in JOptionPane.
Perhaps your answer is available here: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
Or read into this SO question:
How to set jframe look and feel
Use the System Look And Feel.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
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
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.
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.
been trying this for a while now and can't seem to get it to work. I wrote a little GUI app that uses the OS's default Look And Feel. While I wrote it on linux, it is mainly intended to be used on Windows. The JSliders under linux are fine by me, but on windows the thumbs(sliders? I don't know the right word) become very narrow, and they stop displaying the value above the thumb, too. I thought I could get around this problem with something like this:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIManager.getLookAndFeelDefaults().put("Slider.thumbWidth", 20);
But, obviously, it doesn't work. How should I do this? seems like it should be a trivial thing, and I already spent more time on it than I'll ever want to admit.
thanks a lot
Not all LAFs will use the UIManager properties.
I'm not aware of the "thumbWidth" property. Maybe you meant to use the "trackWidth"?
Here is a complete list of the UIManager Defaults.