Explore Java

Be Social. Be Updated.

  • Stumble
  •   
  •   

Using Windows Look And Feel for JButton



An example on using WindowsLookAndFeel for JButton

import javax.swing.*;
import java.awt.*;
class WindowsButton extends JFrame
{
JPanel p;
public WindowsButton()
{

try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}catch(Exception e){}

setTitle("Windows Button");
setSize(400,400);
setLayout(new BorderLayout());
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);

p=new JPanel();
p.setLayout(new GridLayout(10,10));

for(int i=1;i<=100;i++)
{
p.add(new JButton("Button "+i+"\n"));
}

add(p);

}

public static void main(String args[])
{
new WindowsButton();
}
}

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"): Set the default windows look and feel (chosen by your current theme) to the frame (ofcourse for components in the frame too). The class is situated in com.sun.java.swing.plaf.windows package and the name is WindowsLookAndFeel

p.setLayout(new GridLayout(10,10)): Create GridLayout for panel for 10 rows and 10 cols.
Windows Look And Feel - JButton
Windows Button

0 comments:

About This Blog

This blog contains Java Tutorials, Code Samples,demonstrating several concepts in Java. All the code samples are well tested by a team of experts and hence there will be no programmatical errors. We are seamlessly thriving in making the tutorials easier for beginners.

About the Author

was a software and technology enthusiast. He is a 12th grade student and a part time blogger with extreme love in Java programming.Follow him on Google+ and Twitter or befriend him on Facebook and also on