0

I have a question regarding the possibility to dinamically update the visual side of a swing application. I have created a small program, that works without any compile/logic errors and it does it's thing but it has a flaw. It does not automatically update when user clicks on something. Let me explain the issue with the underneath picture

enter image description here

I tried adding a repaint and revalidate to anything. but it doesn't seem to work. they get ignored. Really, I added a repaint/revalidate method to EVERYTHING. Still nothing :)

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
zypa
  • 303
  • 2
  • 13

2 Answers2

0

I suggest adding the action event to the checkbox (I called it fullAutomaticCheckBox and the field txtField):

private void fullAutomaticCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {                                                      
    txtField.setEnabled(fullAutomaticCheckBox.isSelected());
} 

To add the event listener:

    fullAutomaticCheckBox.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            fullAutomaticCheckBoxActionPerformed(evt);
        }
    });
Andrea Annibali
  • 379
  • 2
  • 5
0

I want the text field to enable itself.

Then you add an ActionListener to the check box to enable/disable the text field depending on the state of the checkbox.

once user inputs a number it will repaint dynamically

If you want the screen to repaint, then you need to invoke the "update calculations" code dynamically. So you can add a DocumentListener to the text field. This will generate an event any time the user adds or removes text in the text field.

Read the section from the Swing tutorial on How to Write a DocumentListener for a basic example to get you started.

camickr
  • 321,443
  • 19
  • 166
  • 288