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 524419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:33:58+00:00 2026-05-13T08:33:58+00:00

I have a GUI written using netbeans with a few simple components in place.

  • 0

I have a GUI written using netbeans with a few simple components in place.
I want to be able to draw images (any file type, whatever’s easiest) alongside the GUI components inside the JFrame.

Don’t have to resize them, just draw them as they are, at the x and y location of my choosing.
There will be several images being drawn at each update, some will become hidden and others displayed. The updating will only occur every 5 seconds or so, so it’s being fast isn’t really an issue.

If it would be possible to attach events to the images’ being clicked, that would be nice, but not essential.

This is a supremely simple task that I have as yet been unable to get a simple answer to.

How do I go about doing this?

Thanks

package Pokertable;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* ClientWindow.java
*
* Created on Sep 12, 2009, 9:10:48 PM
*/

/**
*
* @author Robert
*/
public class ClientWindow extends javax.swing.JFrame {

/** Creates new form ClientWindow */
public ClientWindow() {
    initComponents();
}

/** This method is called from within the constructor to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    jScrollPane1 = new javax.swing.JScrollPane();
    jTextField1 = new javax.swing.JTextField();
    jScrollPane2 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jCheckBox2 = new javax.swing.JCheckBox();
    imagePanel1 = new Pokertable.ImagePanel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("Not Logged In");
    getContentPane().setLayout(null);

    jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jTextField1KeyTyped(evt);
        }
    });
    jScrollPane1.setViewportView(jTextField1);

    getContentPane().add(jScrollPane1);
    jScrollPane1.setBounds(0, 540, 170, 22);

    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane2.setViewportView(jTextArea1);

    getContentPane().add(jScrollPane2);
    jScrollPane2.setBounds(0, 440, 166, 96);

    jCheckBox2.setText("Sit Out Next Hand");
    jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jCheckBox2ActionPerformed(evt);
        }
    });
    getContentPane().add(jCheckBox2);
    jCheckBox2.setBounds(0, 410, 113, 23);
    getContentPane().add(imagePanel1);
    imagePanel1.setBounds(130, 130, 100, 100);

    pack();
}// </editor-fold>

private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    // TODO add your handling code here:
}                                          

private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {                                     
    // TODO add your handling code here:
}                                    


/**
* @param args the command line arguments
*/
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new ClientWindow().setVisible(true);
        }
    });
}

// Variables declaration - do not modify
private Pokertable.ImagePanel imagePanel1;
private javax.swing.JCheckBox jCheckBox2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
// End of variables declaration

}

  • 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-13T08:33:58+00:00Added an answer on May 13, 2026 at 8:33 am

    Create your custom component, and add it to the NetBeans pallete:

    public class ImagePanel extends JPanel {
    
      private Image img;
    
      public void setImage(String img) {
        setImage(new ImageIcon(img).getImage());
      }
    
      public void setImage(Image img) {
        int width = this.getWidth();
        int height = (int) (((double) img.getHeight(null) / img.getWidth(null)) * width);
        this.img = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
      }
    
      @Override
      public void paintComponent(Graphics g) {
        g.drawImage(img, 0, 0, this);
      }
    }
    

    I’ve included some simple scaling, you can remove it if you like.

    A bit of explanation now:

    • extending JPanel makes the component conform to the JavaBean spec. If you want to be able to set the img property via the NetBeans property editor, you should define a simpel getter;
    • otherwise you can manually call setImage() and call repaint(), which will make the image draw
    • the overridden paintComponent method is called on each repaint of the component, and there, you can see, you draw your image in the boundries of the current JPanel (ImagePanel)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Thanks for the help folks, I found another way to… May 14, 2026 at 8:16 pm
  • Editorial Team
    Editorial Team added an answer Not sure I see the question. But yeah, that can… May 14, 2026 at 8:16 pm
  • Editorial Team
    Editorial Team added an answer Something like: table = User.__table__ field = table.c["fullname"] print "Type",… May 14, 2026 at 8:16 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.