- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: Mutable ComboBox
Tue, 2010-08-10, 15:25
Hi Rex. Thanks for the response. This is what I originally tried but I got the following exception:
java.lang.RuntimeException: Cannot use this method with a non-Mutable data model.
at javax.swing.JComboBox.checkMutableComboBoxModel(JComboBox.java:773)
at javax.swing.JComboBox.removeAllItems(JComboBox.java:746)
I suppose my question wasn't really can it be done at the moment, as looking at the code, I know it can't. I suppose I was asking if it was planned to be done in the future?
Thanks, Nick.
On 10 August 2010 15:10, Rex Kerr <ichoran [at] gmail [dot] com> wrote:
java.lang.RuntimeException: Cannot use this method with a non-Mutable data model.
at javax.swing.JComboBox.checkMutableComboBoxModel(JComboBox.java:773)
at javax.swing.JComboBox.removeAllItems(JComboBox.java:746)
I suppose my question wasn't really can it be done at the moment, as looking at the code, I know it can't. I suppose I was asking if it was planned to be done in the future?
Thanks, Nick.
On 10 August 2010 15:10, Rex Kerr <ichoran [at] gmail [dot] com> wrote:
The underlying JComboBox can do this via the add/remove Item methods. You can access this directly by using the peer field of the Scala ComboBox.
I am not sure whether this will confuse anything; I haven't tried it myself. But that's the way I'd go. (The Scala wrapper does not provide an equivalent for the add/remove methods.)
--Rex
On Tue, Aug 10, 2010 at 9:52 AM, Nick D'Arcy <nickdarcy [at] gmail [dot] com> wrote:
Hi all.
Is there anyway I can alter the items in a ComboBox once it has been created?
I seem to be running into this problem a lot and my hack of removing the combo box, creating a new one and putting it back into the component is getting a bit tired.... as above other things, you have to set up reactions again.
Thanks, Nick.
Tue, 2010-08-10, 18:47
#2
Re: Mutable ComboBox
Hi,
On Tue, Aug 10, 2010 at 11:34 AM, Rex Kerr <ichoran [at] gmail [dot] com> wrote:
I'm doing exactly that and haven't had any problems.
// creation val combo = new ComboBox(List(/* data */)) { preferredSize = new Dimension(300, 25) maximumSize = preferredSize minimumSize = preferredSize peer.setModel(new DefaultComboBoxModel) // <- to be mutable } // changes combo.peer.removeAllItems() combo.peer.addItem(i)
Regards,Germán
On Tue, Aug 10, 2010 at 11:34 AM, Rex Kerr <ichoran [at] gmail [dot] com> wrote:
You can override the data model using the Java-side methods with
peer.setModel(new DefaultComboBoxModel(/*item array*/))
but again, I don't know whether that will work or cause things to break horribly.
I'm doing exactly that and haven't had any problems.
// creation val combo = new ComboBox(List(/* data */)) { preferredSize = new Dimension(300, 25) maximumSize = preferredSize minimumSize = preferredSize peer.setModel(new DefaultComboBoxModel) // <- to be mutable } // changes combo.peer.removeAllItems() combo.peer.addItem(i)
Regards,Germán
Wed, 2010-08-11, 09:27
#3
Re: Mutable ComboBox
Hi all. Thanks for the suggestions. This does indeed work.
It's a shame I have to go to the peer though. I like the way ListView is done so although it can't be exactly the same, I think ComboBox should should mirror that more closely.
Thanks, Nick.
On 10 August 2010 18:41, Germán Ferrari <german [dot] ferrari [at] gmail [dot] com> wrote:
It's a shame I have to go to the peer though. I like the way ListView is done so although it can't be exactly the same, I think ComboBox should should mirror that more closely.
Thanks, Nick.
On 10 August 2010 18:41, Germán Ferrari <german [dot] ferrari [at] gmail [dot] com> wrote:
Hi,
On Tue, Aug 10, 2010 at 11:34 AM, Rex Kerr <ichoran [at] gmail [dot] com> wrote:
You can override the data model using the Java-side methods with
peer.setModel(new DefaultComboBoxModel(/*item array*/))
but again, I don't know whether that will work or cause things to break horribly.
I'm doing exactly that and haven't had any problems.
// creation val combo = new ComboBox(List(/* data */)) { preferredSize = new Dimension(300, 25) maximumSize = preferredSize minimumSize = preferredSize peer.setModel(new DefaultComboBoxModel) // <- to be mutable } // changes combo.peer.removeAllItems() combo.peer.addItem(i)
Regards,Germán
peer.setModel(new DefaultComboBoxModel(/*item array*/))
but again, I don't know whether that will work or cause things to break horribly.
--Rex
On Tue, Aug 10, 2010 at 10:17 AM, Nick D'Arcy <nickdarcy [at] gmail [dot] com> wrote: