Look and feel setup for different OS - java

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());

Related

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

Look and Feel in Swing

The default Look & Feel of Swing is not good looking for Linux platforms, The target Platforms are Windows and Linux, Can someone suggest are there any library which gives better look and feel similar to components appearing on windows platforms for Linux systems?
For windows, I am using system look and feel, this looks much better than in Linux. Also like to know how to load different look and feel depending on the platform.
You'll need to read the 'howto' for setting the look and feel. Oracle has one here: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
To use GTK, you would use:
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
}
catch (ClassNotFoundException e)
{
}
catch (UnsupportedLookAndFeelException e)
{
}

Changing Java program LookAndFeel doesn't affect

I'm trying to change LAF of my program in this way:
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
} catch (Exception ex) {
Logger.getLogger(MainWin.class.getName()).log(Level.SEVERE, null, ex);
}
But this doesn't affect and program still looks as METAL while this reports "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" that means it must be changed:
UIManager.getLookAndFeel().getClass().getName();
Changing to other LAFs has the same problem!
What's the problem?
Thanks
Do you set look and feel before you create your GUI? Because if your GUI is already created (even if not shown), you have to tell Swing that LAF was updated:
SwingUtilities.updateComponentTreeUI(frame);
GTKLookAndFeel only gets applied if the operating system is Linux.
Using GTKLookAndFeel for a application running on Windows does not change the Look and Feel.
It will still display the Metal Look and Feel.
Note: The GTK+ L&F will only run on UNIX or Linux systems with GTK+
2.2 or later installed, while the Windows L&F runs only on Windows
systems. Like the Java (Metal) L&F, the Motif L&F will run on any
platform.
More info on Modifying the Look and Feel

Open source laf[look n feel] for java swing application

Which are Open source lafs[look n feel] for java swing application?
Substance LAF from Kirill Grouchnikov is the best I know.
Here is a great answer on another question: Java Look & Feel
Edit:
Don't forget the system look and feel:
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {}
Don't forget
Seaglass : a LAF inspired by the OSX theme and, well, you knew it, seaglass (beautiful!)
Nimbus : The standard Java L&F for Java 6

Categories