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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:05:23+00:00 2026-05-13T07:05:23+00:00

I have a GUI window that I’ve created using Netbeans. I then ported the

  • 0

I have a GUI window that I’ve created using Netbeans. I then ported the code into my own program so that I can display .png’s at my will.

However, the GUI components are not displaying, and the window opens up with no size by default.

I need the window to initially open up with the GUI components visible, with the window of the correct size for everything to be visible.

Can anyone help me out?

thanks

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

public class AwtImage extends javax.swing.JFrame {

    private Image img;

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

    public static void main(String[] args){
        AwtImage ai = new AwtImage();
    }

    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();

        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);

        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:
    }               



    public AwtImage() {
        super("Image Frame");
        MediaTracker mt = new MediaTracker(this);
        img = Toolkit.getDefaultToolkit().getImage("C:\\Documents and Settings\\Robert\\Desktop\\ClientServer\\Poker Table Art\\TableAndChairs.png");
        mt.addImage(img,0);
        setSize(600,600);


        initComponents();
        setVisible(true);
        addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent we) {
                dispose();
            }
        });
    }

    public void update(Graphics g){
        paint(g);
    }

    public void paint(Graphics g) {
        if(img != null)
            g.drawImage(img, 0, 10, this);
       // else
        //    g.clearRect(0, 0, getSize().width, getSize().height);
    }
}

alt text http://img41.imageshack.us/img41/9795/openn.png
alt text http://img709.imageshack.us/img709/5716/uponresize.png

  • 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-13T07:05:24+00:00Added an answer on May 13, 2026 at 7:05 am

    There are several problems with the code.

    In addition to the other suggestions of using pack() or setting the frame size “after” adding the components to the frame and just before invoking the setVisible(true) method you need to look at the following.

    The code is based on old AWT painting techniques, which should NOT be used with Swing. You should NEVER override the update() or paint() methods of the JFrame. The reason the child components are not painted is that the paint() method is responsible for painting them but you overrode this default behaviour.

    When using Swing custom painting is done by overriding the paintComponent() method of a JComponent or JPanel, then you add this component to the content pane of the frame. Read the section from the Swing tutorial on Custom Painting for more information and working examples. One of the key points in the tutorial is to provide a preferred size for the component so it can be layed out properly by the layout manager.

    You should NOT be using a KeyListener. Again, this is an old AWT technique. Swing now uses Key Bindings to map KeyStrokes to an Action. Read the section from the Swing tutorial on “How to Use Key Bindings” for more information.

    You should NOT be using a WindowListener to close the frame again this is an old AWT technique. Swing applications now use the frame.setDefaultCloseOperation(…) method to control this.

    The tutorial section on “How to Use Icons” shows you easier ways to load an image.

    So overall I suggested you start by downloading the Swing tutorial to learn the Swing programming techniques. The tutorial covers the basics and many simple examples to get you started.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Couldn't you just play your "boing" sound when contact is… May 13, 2026 at 8:12 am
  • Editorial Team
    Editorial Team added an answer I think you'll have better luck if you search for… May 13, 2026 at 8:12 am
  • Editorial Team
    Editorial Team added an answer I'm not sure from your question if you want to… May 13, 2026 at 8:12 am

Related Questions

I've finally managed to run the QtCreator debugger on Windows after struggling with the
I have a program with a GUI that needs to open a separate window
I hope it is correct term-wise to say that components in a GUI is
i am asking myself if it is possible to somehow create a dynamic gui
The book I've been reading about Django mandates heavy usage of a command line

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.