Re: Setting an icon on a JButton
- From: "hiwa" <HGA03630@xxxxxxxxxxx>
- Date: 25 Dec 2006 20:59:46 -0800
dushkin wrote:
Hello there,You could use a simple JPanel instead of extendint it.
Please review the following code segment....
/*************************************************************/
public class IMIEasternButtonPanel extends JPanel {
private BoxLayout bl = new BoxLayout(this, BoxLayout.LINE_AXIS);
private JButton m_btnUp, m_btnDown;
public IMIEasternButtonPanel(){
setLayout(bl);
setPreferredSize(new Dimension(500,50));
addChilds();
}
public void addChilds(){
boolean b = FilesUtils.isFileExists("up.gif"); //b = true !!!
Icon upIcon = null;
upIcon = new ImageIcon("up.gif");
m_btnUp = new JButton();
m_btnUp.setIcon(upIcon);
m_btnUp.setSize(50, 50);
add(m_btnUp);
/*******************************************************/
Why can't I see the icon on the up button??? Moreover, the button does
not seems to get the correct size as I had set. It is more like a
oblong than a 50X50 square...
Many thanks!
What's the point in extendint it?
Try this:
-------------------------------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
public class IMIEasternButtonPanel extends JPanel {
private JButton m_btnUp, m_btnDown;
public IMIEasternButtonPanel(){
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setPreferredSize(new Dimension(500,50));
addChilds();
}
public void addChilds(){
m_btnUp = new JButton(new ImageIcon("up.gif"));
m_btnUp.setMinimumSize(new Dimension(50, 50));
m_btnUp.setMaximumSize(new Dimension(50, 50));
m_btnUp.setPreferredSize(new Dimension(50, 50));
add(m_btnUp);
}
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
IMIEasternButtonPanel iebp = new IMIEasternButtonPanel();
frame.getContentPane().add(iebp, BorderLayout.EAST);
frame.setSize(500, 500);
frame.setVisible(true);
}
}
.
- Follow-Ups:
- Re: Setting an icon on a JButton
- From: dushkin
- Re: Setting an icon on a JButton
- References:
- Setting an icon on a JButton
- From: dushkin
- Setting an icon on a JButton
- Prev by Date: Setting an icon on a JButton
- Next by Date: Re: please help me out
- Previous by thread: Setting an icon on a JButton
- Next by thread: Re: Setting an icon on a JButton
- Index(es):