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();


}
}


0 Comments:

Post a Comment

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