First things first -- I had posted a question earlier wherein i had asked for help as to why my code was not working and this question is acting upon the advice i got in that question.
My use case is this.
Im writing a MethodEditor
module wherein every Method
is denoted by a custom data object that has 2 data members --
- List of input variable names
- String(name of the result variable that this method sets).
These Method
objects are generated as a result of filling out some data on a JDialog
.
These Method
objects are stored in a container that has 1 data member that is a List<Method>
The container resides in a controller JPanel
from where the aforementioned JDialog
is invoked.
From a UI perspective I want to display every Method
object in the form of a Jbutton on click of which a JDialog
will open and allow the user to edit it.
The MethodEditor
acts on a List and generated a vertical arrangement of JButtons, 1 for each Method
in List<Method>
. This List<Method>
is passed to the MethodEditor
from the aforementioned controller JPane
.
I had in my earlier question implemented the MethodEditor
as a JPanel
that would add a PropertyChangeListener
to the List<Method>
and would repaint
itself everytime there was a PropertyChange
event but my approach did not work, the repaint would not happen.
Is there another way to get my use case implemented or is there any fix that i could do to my code posted in the earlier question ?
I'm really lost (from your last three question),
may be, could we imagine that you have got three separated
Models
for one GUI, in this case doesn't important if you want to change number of elements in the GUI, or change properties for oneJComponent
,output from
PropertyChangeListener
quite guarantee that output could be done onEDT
Please verify that the PropertyChangeEvent does not fire. If it does fire, but the repaint does not happen, it might help to postpone the repaint a bit like this:
If the change event does not fire - disregard all after 'Please' ;)
Your problem has been mentioned before as has its solution. You must actually add or remove the component to your observer panel from within the PropertyChangeListener. Calling
revalidate()
andrepaint()
will not magically add or remove components unless you explicitly do this before these methods are called.For example: