Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem displaying Images on JToolBar buttons.  RSS feed

 
swapna sivaraju
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
Iam trying to display images on my ToolBar buttons.
The First button gets the image(1.gif) but no images are displayed on the rest of the buttons..can anyone tellme the reason.
Here is the code--
Class TestClass extends JFrame
{
JToolBar toolBar;
Action Button_1,Button_2,Button_3,Button_4;
public TestClass()
{
super();
toolbar =new JToolBar();
Icon ic1=new ImageIcon("C:\\1.gif");
Button_1 = new AbstractAction("1",ic1) { public void actionPerformed(ActionEvent e) {
}
};
Icon ic2=new ImageIcon("C:\\2.gif");
Button_2 = new AbstractAction("2",ic2) {
public void actionPerformed(ActionEvent e) {
}
};
Icon ic3=new ImageIcon("C:\\3.gif");
Button_Save = new AbstractAction("3",ic3) {
public void actionPerformed(ActionEvent e) {
}
};
Icon ic4=new ImageIcon("C:\\4.gif");
Button_Print = new AbstractAction("4",ic4) {
public void actionPerformed(ActionEvent e) {
}
};
toolbar.add(Button_1).setToolTipText("1");
toolbar.add(Button_2).setToolTipText("2");
toolbar.add(Button_3).setToolTipText("3");
toolbar.add(Button_4).setToolTipText("4");
getContentPane().add(toolBar);
pack();
setVisible(true);
}
public static void main(String sr[])
{
new TestClass();
}
}
The *.gif files are in the same directory as the class files.
Thanks
 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swapna,
Barring a few typos, I don't see any reason why the images won't show up - are you sure you have those image files in there & are they named correctly ( the extensions I mean ).
HTH
Ashish Hareet
 
swapna sivaraju
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
The files are in right path and the extensions are also correct.
help me out with this as iam unable to get the
reason of this odd behaviour.
Thanks
Swapna
 
swapna sivaraju
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks i could solve this..i think there was some problem with the format of *.gif files.
When i loaded the files again,it worked.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!