Skip to content
Advertisement

How to update values of a JFrame main after using a JDialog of Java Swing?

I have a main window called MainFrame which is a jForm to which I update the data depending on a timer, but the problem is that I cannot update the data in the same MainFrame after using the jdialog, since I end up creating another duplicate window, but with the data changed, one with the original timer and the other with the new timer, I know that I can close the first window with dispose() and then keep the second, but I would like to avoid changing windows so much

the code with which I create another window when pressing the jDialog button is the following

JavaScript

Is there any alternative to update the window? something like mainFrame.update(); or maybe send the value of the jTextField from the jDialog to mainFrame? since the previous code creates another MainFrame for me.

Method main setLabel and Timer.start/stop

JavaScript

setLabelText is a method set of label

JavaScript

Any help would be appreciated.

Advertisement

Answer

Thanks for the update, and I found another solution without using an OptionPane from this question: programmatically close a JPanel which is displayed in JDialog.

I cannot replicate your codings

Start with the MainFrame, assuming you opened the JDialog by clicking on a button and wants to setText() to label lbSomething:

JavaScript

Then about the JDialog (with simple input detection):

JavaScript

Hope this answer helps you well.


Would be better if you displayed the source code, but a simple solution to update values to an existing JFrame is by using setText() and getText().

For example:

JavaScript

If you created a self-defined JDialog, it is about to transfer the input value when closing the JDialog, and that could be a different question.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement