Mithun's Memoirs

« JavaFX rocks | Main | Pure JavaFX Demo »
Saturday Dec 08, 2007

JavaFX Look and Feel

Im my previous post, I demonstrated how easy it is to create applications using JavaFX script with NetBeans IDE. I shall extrapolate this knowledge to include customized Look and Feel (L&F) using the existing Swing Look and Feels. If you remember it well, the earlier demo used the default "Metal" look and feel, which I detest. I find it somewhat ugly. Windows Look and Feel is somewhat better, but JGoodies L&F is cool. I shall use the Windows L&F.

The listing is pretty same as the previous demo. I dont need the function square() here, so I have removed it. Here, I shall focus entirely and just on the L&F. The procedure is same as the previous post. The source listing is somewhat different.

/*
 * TestLAF.fx
 *
 * Created on 08.12.2007, 10:23:22
 */

package lookandfeel;

/**
 * @author Mithun Sridharan
 */

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.lang.System;
import java.lang.Math;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import javax.swing.UIManager;


    var frame = new JFrame();
    frame.setResizable(false);
    var n = 0;
    var button = new JButton("Press me";);
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel";);    
   
   
    frame.getContentPane().add(button);
    button.addActionListener(new ActionListener() {
        operation actionPerformed(event) {
            System.out.println(n);
            n++;
            }
            });
        frame.pack();
        frame.setVisible(true);

The code is pretty self-explanatory. I've imported the UIManager and the WindowsLookAnd Feel classes and have used them using the code:

    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel";);    

On compiling and running the example, the UI changes from:


to:

 

Isn't it simple. With the existing Swing know-how, its just easy to use JavaFX. 

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed