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

  • Home
  • SEARCH
  • 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 983661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:53:41+00:00 2026-05-16T04:53:41+00:00

I am trying to make some small additions to some old java code that

  • 0

I am trying to make some small additions to some old java code that does not support swing. I need to add a small dialog that contains a panel which has a checkbox and a couple text fields. When the user clicks on the checkbox I want to disable or enable the checkboxes. This part seems to work well but the text fields are not properly getting redrawn. When I click the checkbox the fields do not appear to become enabled but if I then click on the panel or the text field you see that they are enabled (the opposite is also true, when I un-check the checkbox the fields still look enabled until you try and click on them and they become ghosted and do not become selected). I use the setEnabled(boolean) to set the status of the fields. I have tried calling repaint and validate on both the fields and the panel after changing the status and this does not seem to work. I have also tried to have the fields request focus and this did not work. Anyone have any other ideas?

 //The class that contains all of this is of type Window
 //Declaration of the components
  private Panel _inputPanel;
  private TextField min , max;
 //This method adds to two text fields
 public void addMinMaxtextFields(String min, String max) {
    TextField minField = new TextField(min);
    TextField maxField = new TextField(max);

    this.min = minField;
    this.max = maxField;
    this.min.setEnabled(false);
    this.max.setEnabled(false);
    _inputPanel.add(minField);

    _inputPanel.add(maxField);


}
//listener for the checkbox
public void itemStateChanged(ItemEvent e) {
    Component[] components = _inputPanel.getComponents();

    min.setEnabled(!min.isEnabled());
    min.setVisible(true);
    min.validate();
    min.repaint();

    _inputPanel.validate();
    _inputPanel.repaint();
    this.pack();

    this.setSize(this.getWidth(), this.getHeight());

    this.validate();

    this.repaint();
    /* do nothing */
}
  • 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-16T04:53:42+00:00Added an answer on May 16, 2026 at 4:53 am

    You will need to call update(Graphics g) on Panel after setEnabled(boolean) is called.

    check :
    http://download-llnw.oracle.com/javase/1.4.2/docs/api/java/awt/Container.html#update(java.awt.Graphics)

    I tried following code (built from code you provided), Its working fine.

    import java.awt.Checkbox;
    import java.awt.Component;
    import java.awt.Dialog;
    import java.awt.Frame;
    import java.awt.Panel;
    import java.awt.TextField;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    
    public class CheckUI extends Dialog implements ItemListener {
    
        // The class that contains all of this is of type Window
        // Declaration of the components
        private Panel _inputPanel;
        private TextField min, max;
        private Checkbox cb;
    
        public CheckUI(Frame owner, boolean modal) {
            super(owner, modal);
            _inputPanel = new Panel();
    
            this.add(_inputPanel);
            addMinMaxtextFields("min", "max");
        }
    
    
        // This method adds to two text fields
        public void addMinMaxtextFields(String min, String max) {
            cb = new Checkbox();
            cb.addItemListener(this);
            TextField minField = new TextField(min);
            TextField maxField = new TextField(max);
    
            this.min = minField;
            this.max = maxField;
            this.min.setEnabled(false);
            this.max.setEnabled(false);
            _inputPanel.add(minField);
    
            _inputPanel.add(maxField);
            _inputPanel.add(cb);
    
        }
    
        // listener for the checkbox
        public void itemStateChanged(ItemEvent e) {
            Component[] components = _inputPanel.getComponents();
    
            min.setEnabled(!min.isEnabled());
            min.setVisible(true);
            min.validate();
            min.repaint();
    
            _inputPanel.validate();
            _inputPanel.repaint();
            this.pack();
    
            this.setSize(this.getWidth(), this.getHeight());
    
            this.validate();
    
            this.repaint();
            /* do nothing */
        }
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            Frame parent = new Frame();
            parent.setVisible(true);
            parent.setExtendedState(Frame.MAXIMIZED_BOTH);
            parent.pack();
    
            CheckUI ui = new CheckUI(parent, true);
            ui.pack();
            ui.setVisible(true);
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 489k
  • Answers 489k
  • 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 Complex view hierarchies and alpha blending will always kill your… May 16, 2026 at 8:53 am
  • Editorial Team
    Editorial Team added an answer If I understand your question correctly, you can use recursion… May 16, 2026 at 8:53 am
  • Editorial Team
    Editorial Team added an answer Use the Toast's setView(view) function to supply a View with… May 16, 2026 at 8:53 am

Trending Tags

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

Top Members

Related Questions

No related questions found

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.