In scala.swing, I can add a component to a container like so:
new Frame {
contents += label
}
but sometimes I'd like to clear the contents of a container and replace them with new components. Based on the docs, I should be able to do:
frame.contents.remove(0)
or
frame.contents.clear
but neither of those compile ("clear/remove is not a member of Seq[scala.swing.Component]").
How can I resolve this? Also, it seems that I can't call frame.contents += blah
after intialization. If this is so, how do I add a new component to a Container?
If you're talking about
Frame
specifically, you can only add one item, so use the methodand you should be good. Try this out in the REPL (one line at a time so you can see what's going on):
If you're using something that is intended to have multiple items like a
BoxPanel
,contents
is aBuffer
so you can add to it and remove from it:If you have something else like a
Component
that you're extending, it is your job to overridecontents
with a buffer or have some other way of modifying it (or inherit fromSequentialContainer
as J-16 said).