Reference Swing components with variables - From blog comment.

14 views
Skip to first unread message

TimDalton

unread,
May 19, 2008, 1:36:58 PM5/19/08
to scala-squib
Is there a way to reference Swing components with variables? I like to
split my screen in 3 panels: top, center and bottom. I build each of
them in a different method and aggregate them in another panel with a
specific layout. That keeps the code clearer for me. The Groovy
SwingBuilder has a 'widget' pseudo component for that. See code below.
Sorry if it formats badly on the blog, I don't know where to post my
question, there is no forum on code.google for the Squib project.

// Build a panel with a table used to select the attribute to be used
as keys in the UPDATE statement
// The table as a column with a checkbox and another with the
attribute names
def topPanel = setupAttributesAsKeysPanel(swingBuilder)

// Panel with the attributes to be updated and "Select all" and
"Deselect all" buttons
// The table as a column with a checkbox and another with the
activities attribute names to be updated
def centerPanel = setupAttributesToUpdatePanel(swingBuilder)

// Panel with "Update Activities" and "Close" buttons
def bottomPanel = setupButtonsPanel(swingBuilder)

// TODO: adjust the location dynamically
// With a JFrame, we need to enable the "Update Activities" button in
the "ODBC Export" parent window in the close action handler
// frame = swingBuilder.frame(title: ODBCUPDATE, location: [300,100],
windowClosing: closeButtonClicked,
frame = swingBuilder.dialog(owner: parent.frame, modal: true, title:
ODBCUPDATE, location: [300,100],
windowOpened: onWindowOpened, windowClosing: doCloseWindow,
defaultCloseOperation: WindowConstants.DO_NOTHING_ON_CLOSE, pack:
true, show: false)
{
panel(border: emptyBorder(top:3,left:3,bottom:3,right:3))
{
borderLayout()
box(axis: BoxLayout.Y_AXIS)
{
widget(topPanel)
widget(centerPanel)
}
widget(bottomPanel, constraints: BorderLayout.SOUTH)
} // panel
} // frame
// Prevent the user to make the window any smaller than the minimum
required to show all elements. The window can still be made larger
Dimension size = frame.getSize()
size.width = size.width + 100 // Make it a little bit fatter
frame.setMinimumSize(size)
frame.setSize(size)
frame.show()

Adek336

unread,
Jun 17, 2008, 6:46:29 PM6/17/08
to scala-squib
how about

frame(...
contents( panel( "myPanel1", ....))).pack

val myPanel1Handle = panel.id("myPanel1") ?
Reply all
Reply to author
Forward
0 new messages