I'm facing a problem when applying a native Look & Feel to my JFrame, all text (except HTML formatted JLabel) have an ugly bold font.
The very simple UI in the following code sum up all the differences I can see with this L&F :
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
public class HelloWorld extends JFrame {
public HelloWorld() {
Box b = Box.createVerticalBox();
// Labels
JLabel bold = new JLabel("I'm bold !");
JLabel notBold = new JLabel("<html><em>I'm not bold !</em></html>");
b.add(bold);
b.add(notBold);
// Scrollbars example
JPanel scrollViewPort = new JPanel();
scrollViewPort.setPreferredSize(new Dimension(400, 400));
JScrollPane scroll = new JScrollPane(scrollViewPort);
b.add(scroll);
add(b, BorderLayout.CENTER);
// Bold menu
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("Menu");
JMenuItem item = new JMenuItem("Item");
menu.add(item);
menubar.add(menu);
setJMenuBar(menubar);
setPreferredSize(new Dimension(200, 200));
pack();
}
public static void setNativeLAF() {
// Native L&F
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.out.println("Unable to set native look and feel: " + e);
}
}
public static void main(String[] args) {
// setNativeLAF();
HelloWorld app = new HelloWorld();
app.setVisible(true);
}
}
See the difference :
with native L&F (GTK+)
with Metal L&F
by commenting out the setNativeLAF()
call.
I'm applying the native look and feel right when my application starts, before any window appears. The UIManager
gives me GTK+ (com.sun.java.swing.plaf.gtk.GTKLookAndFeel)
as the native look and feel, which is ok since i'm using a Gnome 3 desktop.
I have three problems with this right now :
- The GTK+ look and feel doesn't looks like the GTK theme (see the scrollbars)
- The JMenuBar seems disabled (not the case with the Metal L&F)
- The font is bold ! (same problem with Metal L&F, but fixable)
Any help or explanation about why the GTK+ L&F does that on my system whould be appreciated.
Edit: Here is what a "classic" application looks like on my system in eclipse.
JFrame.setDefaultLookAndFeelDecorated(true);
is there any difference, as Andrew mentioned your 2nd. screenshot is shot to the dark, on ecplipse sited is described used look and feel for concrete native os – mKorbel