Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why Won't it work?

Status
Not open for further replies.

Renidrag

Programmer
Jul 16, 2002
5
0
0
CA
I am new to java and I am working through "Java How to Program - Third Edition" programming book I have "Forte for Java 4 - Community Edition" installed and everything was working fine until I got to chapter 12 and started working with Icon and ImageIcon each app that I write from the book compiles fine and runs but without the Icon(picture) the first app was testing JLabels and using new JLabel("String here", Iconpichere, postitionoftext) - that worked but now picture now I have this one testing JButtons and it compiles fine runs fine but - Guess what? NO ICON, can some one please give me a clue here? (God, I love Visual Basic)

Here is the Code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
*
* @author administrator
*/
public class ButtonTest extends JFrame {
private JButton plainButton;
private JButton fancyButton;

/** Creates a new instance of ButtonTest */
public ButtonTest() {
super("Testing Buttons");

Container c = getContentPane();
c.setLayout(new FlowLayout());

// create buttons
plainButton = new JButton("Plain Button");
c.add(plainButton);

Icon bug1 = new ImageIcon("myIcona.gif");
Icon bug2 = new ImageIcon("myIcona2.gif");
fancyButton = new JButton("Fancy Button", bug1);
fancyButton.setRolloverIcon(bug2);
c.add(fancyButton);

// Create an instance of inner class ButtonHandler
// to use for button event handling
ButtonHandler handler = new ButtonHandler();
fancyButton.addActionListener(handler);
plainButton.addActionListener(handler);

setSize(275, 100);
show();
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ButtonTest app = new ButtonTest();

app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
}

// inner class for button event handling
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "You pressed: "
+ e.getActionCommand());
}
}
}
 
as I said in your other post it could be a size issue. If the component you are putting the Icon onto is not big enough to fit it on, it just won't display rather than automatically resizing the imaging to fit.

use the

setMaximumSize()
setMinimumSize()
setPreferredSize()

methods of the JLabel to experiment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top