Monday, December 14, 2009

Java Look and Feel

We can modify the look and feel of java GUI components,Here is an example used to implement the look and feel concepts in java programs.

Using below code we can set the operating systems look and feel.

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class LookAndFeel {
    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            // UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createTheGUIComponents();
            }

            private void createTheGUIComponents() {
                // Your implementation here…
            }
        });
    }
}

We can also set the lot of GUI skins using substance.jar.

Download the latest substance.jar using below link

http://weblogs.java.net/blog/2005/12/29/swinging-java-ides

Add the above jar file in java classpath.

Sunday, November 15, 2009

Java Swing - Icon as JButton

This section illustrates you how to show the icon on the button in Java Swing without border.
Example code.


import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Image;


import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;


public class IconButton extends JDialog {


public IconButton() {


JLabel filename = new JLabel("File Name");
JTextField filenameLoc = new JTextField(10);
Icon image = new ImageIcon(
"url of the image");
JButton iconButton = new JButton(image);
iconButton.setBorderPainted(false);
iconButton.setContentAreaFilled(false);
Container con = getContentPane();
con.setLayout(new FlowLayout());
con.add(filename);
con.add(filenameLoc);
con.add(iconButton);


setLayout(new FlowLayout());
setSize(500, 300);
setVisible(true);
}
public static void main(String[] args) {
IconButton obj = new IconButton();


}
}


Bookmark and Share
Hihera.com
Increase Page Rank Google
TopBlogDir.blogspot.com button
Best Indian websites ranking
Tips for New Bloggers
TopOfBlogs
The Link Exchange - Your ultimate resource for link exchange!

About This Blog

TopOfBlogs

FEEDJIT Live Traffic Feed

  © Blogger template Webnolia by Ourblogtemplates.com 2009

Back to TOP