Problem with SWT and Layouts
- From: "Mikko Tanskanen" <mikko.tanskanen@xxxxxx>
- Date: Thu, 29 Dec 2005 21:26:55 +0200
I'm coding with SWT and I came across a problem with layouts. I have a
shell, which has a sashForm, which has two sashForms. Another one of these
has yet another sashForm within it. Now, this third sashForm has a
Composite(GridLayout), which consists of several Composites. These
Composites have a rowLayout. The Rowlayout has three Labels. But any changes
I make to rowLayout doesn't seem to effect on the appearance of the row. And
I don't seem to be able to add rowData to a Label within this rowLayout.
For example, I try to get labels in the middle, but horizontalAlignment =
GridData.CENTER does nothing.
Nor does playerLayout.justify = true;
Here's some code example:
----
// Let's create a sash form for whole area
wholePane = new SashForm(shell, SWT.HORIZONTAL);
// Now let's divide thw whole area in two vertically
// Left pane is for gametable and player's cards
leftPane = new SashForm(wholePane, SWT.VERTICAL);
rightPane = new SashForm(wholePane, SWT.VERTICAL);
....
// First, on the left: name of the game comes on the top
Label gameName = new Label(leftPane, SWT.CENTER);
// Next is the actual game table
gameTablePane = new SashForm(leftPane, SWT.HORIZONTAL);
// Then we make some room for the error texts
errorPane = new SashForm(leftPane, SWT.NONE);
// And player's own cards are on the bottom
cardsPane = new SashForm(leftPane, SWT.HORIZONTAL);
....
leftPlayers = new Composite(gameTablePane, SWT.NONE);
middleArea = new Composite(gameTablePane, SWT.NONE);
rightPlayers = new Composite(gameTablePane, SWT.NONE);
....
// Let's set a gridlayout for players
GridLayout playersLayout = new GridLayout();
playersLayout.numColumns = 1;
leftPlayers.setLayout(playersLayout);
middleArea.setLayout(playersLayout);
rightPlayers.setLayout(playersLayout);
....
// A player is a rowlayout, which consists of two decks and a player's name
RowLayout playerLayout = new RowLayout();
playerLayout.wrap = true;
playerLayout.pack = true;
playerLayout.justify = true;
playerLayout.type = SWT.HORIZONTAL;
playerLayout.spacing = 5;
playerLayout.marginLeft = 5;
playerLayout.marginRight = 5;
playerLayout.marginBottom = 5;
// And add some style to the components
GridData playersData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
playersData.horizontalAlignment = GridData.CENTER;
playersData.grabExcessHorizontalSpace = true;
playersData.horizontalIndent = 5;
// a Composite for a player
Composite newPlayerArea = new Composite(leftPlayers, SWT.CENTER);
newPlayerArea.setLayout(playerLayout); // Doesn't work, no effect what so
ever
// deck of cards
Label cards = new Label(newPlayerArea, SWT.CENTER);
cards.setImage(image);
// Name of the player
Label name = new Label(newPlayerArea, SWT.CENTER);
name.setText("player");
name.setLayoutData(playerLayout); // ClassCastException here, why?
// a card that player has hit
Label card = new Label(newPlayerArea, SWT.CENTER);
card.setImage(image2);
----
I know, very complicated. But I'm desperate.
--
"Äijät nää, ei lähde täältä mihinkään,
äijät nää vaan humppaa jyskyttää" -Eläkeläiset
Mikko Tanskanen - Humpparitari/ETOn tiedotusvastaava/TiTen lemmikkiKirahvi
.
- Prev by Date: Re: How to enter characters beyond keyboard into JTextField?
- Next by Date: Newbie Problem with Java Label
- Previous by thread: How to enter characters beyond keyboard into JTextField?
- Next by thread: Newbie Problem with Java Label
- Index(es):
Relevant Pages
|