Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

panel and image problem

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I basically have 2 problems now. Firstly the image doesnt appear on the Panel unless I resize the window, and when i move the dialog box off the screen, the image gets erased. similar to the eraser in paintbrush. I have tried doing repaint() and nothing.

And finally, the functionality is lost in the main frame when i close the dialog box

please help!!

thanks

This is a code snippet from the JFRAME that calles the dialog

class ButtonActionListener
implements ActionListener {
public void actionPerformed(ActionEvent event) {

DialogBox dialog = new DialogBox (frame, true);
dialog.setSize(100,100);
dialogsetVisible(true);



}
}

This is a snippet of the dialog. I have called this class DialogBox

private void buildGui() {

GridBagConstraints gc = new GridBagConstraints();

Container c = this.getContentPane();

c.setLayout(new GridBagLayout());

this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);


ImageIcon image;

String image= getPic(1);


ImageIcon icon = new ImageIcon(getClass().getResource(image));

JLabel iconLabel;

iconLabel = new JLabel(icon);

JPanel panel = new JPanel();

panel .add(iconLabel, BorderLayout.NORTH);
JButton button = new JButton("Answer");
gc.gridx = 0;
gc.gridy = 0;

c.add(panel , gc);

gc.gridx = 0;
gc.gridy = 1;
gc.ipady = 0;

c.add(button, gc);


this.pack();

}
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
alun groome
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply, I tried your code out, and i am still having the exact same problem???

cheers
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic