Sunday 15 September 2013

java - GridBagLayout misbehaving. Horizontal distribution problems -


I'm trying to get it:

  | --0-- | --1-- | --2-- | --3-- | --4-- | --5-- | --6-- | --7-- | --8-- | - 9-- | 0 | | JLabe | L ---- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | 1 | | | JLabe | L ---- | ----- | ----- | ----- | ----- | ----- | ----- | 2 | | | | JLabe | L ---- | ----- | ----- | ----- | ----- | ----- | 3 | | | | JLabe | L ---- | ----- | ----- | ----- | ----- | ----- |   

That which I have so far received, is as close as what I can do later.

  center.setLayout (centerLayout); Jepiel [] card = new jpn [1]; // update as long as this, ultimately scoreboard. LNGHT card [0] = new JPNL (); Grid Background Card Cardout = New GridBackout (); Card [0] .setLayout (cardLayout); CardLayout.setConstraints (Winner, New Gridbag Consultants (0, 0, 10, 1, 1, 0, Gridbag Consultants. FIRSTELETTR, Gridbag Console.NOn, New Inset (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0) ); Card [0] .add (winner); CardLayout.setConstraints (name, new gridbag consultants (1, 1, 9, 1, 0.8, 0, gridbag consultants, LINE_START, gridbag console.NOn, new inset (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) 0 ); Card [0] (name) .add; CardLayout.setConstraints (New Gridbag Consultants (2, 2, 8, 1, 0.7, 0, Gridbag Consultants. LINE_START, Gridbag Consultants.NO.N, New Insets (0,0,0,0), 0, 0)); Card [0] .add (with); CardLayout.setConstraints (Score, New Gridbag Consultants (2, 3, 8, 1, 0.7, 0, Gridbag Consultants. LAS T_LINE_START, Gridbag Consultants.NOn, New Inset (0,0,0,0,0,0,0,0,0,0,0, 0, 0) ); Card [0] .add (score); Center.add (Card [0]; "Card 1"); . Add this.getContentPane () (middle);   

And for some reason it looks like this:

  | --0-- | --1-- | --2- - | --3-- | --4-- | --5-- | --6-- | --7-- | --8-- | --9-- | 0 | JLab | L ---- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | 1 | JLab | L ---- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | 2 | JLab | L ---- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | 3 | JLab | L ---- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | ----- | Perhaps it is a more appropriate way to keep my text out of the use of GridBagLayout (it needs to work on different resolutions, so that Layout Manager should be flexible anytime)   

/ P>

1) Naming a gridbaglayout variable "cardless" is not the best idea, IMO .

2) Since you have given only one code snippet and none has provided it, I can only guess based on the "pictures" that you provided. GridBagLayout requires a component in each row / column so that it can be set to size. A given column will be a broad favorite size component found in that column. If it goes for height too, depending on the picture of your results, there is no component whose favorite width is in column 0. An alternate solution is to do a Box.createHorizontalStrut (someWidth) in the desired column.

No comments:

Post a Comment