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)
{
}
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'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
I am building an application in java swing and I am using the following code to give the UI a native OS look
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
On a OS X, the look is fine, but on windows (XP and 7) the buttons look like this.
alt text http://img710.imageshack.us/img710/8735/buttonsoc.png
I have used this exact same code on other projects and it works fine. But in this particular project I get a completely different look.
I am using Java 1.6
Thanks in advance!
Are you possibly creating your GUI elements before actually setting the L&F? If you already created (e.g.) JButton instances and called methods on them, they allocate their UI peer - changes to the L&F after that won't affect the already created instances.
This would explain why it works on Mac (the L&F defaults to Mac on Apple's JVM IIRC), but not on Windows. You can test this quickly if you move setting the L&F directly into your main method as the very first call (this assuming your main class does NOT contain any statically initialized GUI instances of course).
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