Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

image that I want to add to existing JLabel does not display

$
0
0
I want to display the image that is saved exactly where all my text files are and the name of the image is: banana.jpg
I don't want to make another class for displaying it so I tried to add a method.
both the JLabel and the JPanel that I use in my code already exist (I used netbeans and just dragged them in :/
Can you please help? assignment is due in 2 days :(
[ private void DisplayProductjButtonActionPerformed(java.awt.event.ActionEvent evt) {
ProductPriceVATjTextField.setVisible(true);
ProductPriceVATjLabel.setVisible(true);
MinStockjTextField.setVisible(false);
MinimumStockjLabel.setVisible(false);
MaxStockjTextField.setVisible(false);
MaximumStockjLabel.setVisible(false);
AddEditProductjPanel.setVisible(true);
String[] delimiter = (ProductjList.getSelectedValue().toString()).split(" ");

theProductList.searchProducts(delimiter[0],ProductIDjTextField, ProductNamejTextField, ProductManufacturerjTextField,
ProductSupplierjTextField, ProductEXPdatejTextField, ProductWeightjTextField, ProductPricejTextField,
ProductPriceVATjTextField, MinStockjTextField, ActualStockjTextField, MaxStockjTextField);
ProductEditjButton.setVisible(true);
ProductAddjButton.setVisible(false);
//Display the image
showImage();

}
public void showImage(){
java.net.URL imageURL = getClass().getResource("banana.JPG");
JLabel ProductImagejLabel = new JLabel(new ImageIcon(imageURL));
JPanel ProductPanel = new JPanel();
ProductPanel.add(ProductImagejLabel);
add(ProductPanel);//, BorderLayout.CENTER
//setSize(500, 500);
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
//older code below:
//String imgString = "banana.jpg";
//java.net.URL imageURL = getClass().getResource("im.JPG");
//ImageIcon image = new ImageIcon(getClass().getResource(imgString));
//ProductImagejLabel = new JLabel(image);
//add(ProductImagejLabel);
}]

Viewing all articles
Browse latest Browse all 51036

Trending Articles