I’m currently building an application and it has a JFrame and a JDialog. The JFrame has a JList called:
JList lstMainVenuesEvents = new JList();
And I’m trying to get the value of lstMainVenuesEvents by using:
lstMainVenuesEvents.getSelectedIndex();
I can get the value perfectly fine on my JFrame, but how do I pass it to my JDialog? I thought about creating a setter method in one of my class files and then just getting that value from my JDialog file, but surely there’s an easy way? Is it possible to just have a method of some sort that passes the data from the JFrame to the JDialog like a POST request in PHP?
Apologies if I’ve missed anything crucial out.
Update: here’s the code for my JList and JDialog show.
JList lstMainVenuesEvents = new JList();
lstMainVenuesEvents
.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
// stop from firing twice
if (e.getValueIsAdjusting()) {
EventModify evtWindow = new EventModify();
evtWindow.setVisible(true);
}
}
});
I can’t be confident it’s “right” but an inversion of control sort of approach usually reduces passing values around.
Assuming the value
lstMainVenuesEvents.getSelectedIndex()is used on a particular action/event in theJDialogyou could set anActionListenerfrom theJFrame.