Swing Component Alignment

42 Aufrufe
Direkt zur ersten ungelesenen Nachricht

bertzzie

ungelesen,
15.11.2012, 01:55:3615.11.12
an scala...@googlegroups.com
Hi,
I'm learning how to build GUI using the standard Swing widget on Scala. Here's what I want to do:



I've had success in **creating** the components, but failed on **aligning** it. All of my components are aligned centered, not like what I want (Button1 on left, table on center, and button2 on right). I can't find much information about Scala's Swing either. Most of the search result is about Java's (which I don't know anything about). What should I do to force the alignment?

Here's the code:

    contents += new BoxPanel(Orientation.Vertical) {
        contents += new Button("Button 1")
        contents += new Table(3, 3)
        contents += new Button("Button 2")
    }

The result:



Thanks before.

(I've cross posted from Stackoverflow (original thread) because there seems to be no answer there. Please tell me if this is not allowed. Thanks before).

Stefan Hoeck

ungelesen,
15.11.2012, 02:28:3715.11.12
an scala...@googlegroups.com
BoxPanel might be not flexibel enough for what you want. If you want flexibility, go for GridBagPanel. It uses a GridBagLayout (documented in Java's Swing documentation). It's more complex to use than a BoxLayout, but it gives you (almost) complete freedom about how your components are aligned. See also:

http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html

By the way, if you just want to align your components in a horizontal line (Button1 on the left, table in the middle and Button2 on the right), you might try
new BoxPanel(Orientation.Horizontal)
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten