Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4343210
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:43:10+00:00 2026-05-21T11:43:10+00:00

If I run it from netbeans, sometimes it draws the images as intended.. but

  • 0

If I run it from netbeans, sometimes it draws the images as intended.. but sometimes I get only the main window, and the “start” button after I move my mouse.

public class my_gui extends JFrame {
    public my_gui() {
        setTitle("Broscute 1.0 :p");
        setSize(954, 320);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setResizable(false);
        setIconImage(Toolkit.getDefaultToolkit().getImage("src/img/test.png"));
        setVisible(true);
        initUI();
    }
    public final void initUI() { //ui here
        setLayout(null);
        setLocationRelativeTo(null);
        JPanel panel = new JPanel();
        panel.setLayout(null);
        panel.setBounds(0, 0, 954, 320);
        getContentPane().add(panel);
        JButton button = new JButton("Start!");
        button.setBounds(0, 0, 954, 40);
        final ImagePanel[] label = new ImagePanel[4];
        int i, j;
        for(i=40, j=0;i<=220;i+=60, j++){
            label[j] = new ImagePanel(0, i);
            label[j].setBounds(0, 0, 954, 320);
            panel.add(label[j]);
        }
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                label[3].X += 100;

            }
        });
        panel.add(button);
    }
}
class ImagePanel extends JComponent{
    public int X, Y;
    float v = 10;
    private BufferedImage image;
    ImagePanel(){}
    public ImagePanel(int x, int y) {
        X = x; Y = y;
       try {                
          image = ImageIO.read(new File("src/img/broasca.png"));
       } catch (IOException ex) {
            // handle exception...
       }
    }
    @Override
    public void paintComponent(Graphics g) {
        super.paintChildren(g);  //a friend told me I should put it here
        g.drawImage(image, X, Y, this); // see javadoc for more info on the parameters
        repaint(); //I think this should go here
    }
}

Running it outside the IDE, it wasn’t able to find the images.

What am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:43:11+00:00Added an answer on May 21, 2026 at 11:43 am

    Don’t show the dialog until all the initialization is done, ie move the setVisible to the last method in the constructor.

    for better reuse, don’t have the JFrame derived class call setVisible(true) at all, let the client do it.

    The problem is, once you show the window, any changes you make to the window MUST be done on the GUI thread, or else you will get spurious problems like you are seeing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run Tomcat 6.0.18 from Netbeans 6.7 but getting the following
Following program runs fine with Netbeans IDE but when i try to run from
When you run from the command line $ cython -a mycode.pyx you get a
I am creating a site for me only that will run from my server.
My program has the following lines, works fine when run from Netbeans, JButton Button_1=new
I am trying to Run (F6) a Rails application from NetBeans 6.8 and when
I am trying to run Selenium tests (PHP) from the command-line. I can only
When I build / run my applet, made from the NetBeans Applet Form I
I've created a new J2SE project in NetBeans, and I can run it from
After substantial effort getting clang and libc++ to compile, run, integrate with NetBeans, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.