Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java: GUI и Java FX приложения > Пропорциональный лаиаут


Автор: PashaOvechkin 25.3.2010, 16:58
Привет! Нужно что то вроде пропорционального лаиаута по оси х.

Есть прямоугольная панель. Нужно что бы 1/4 её часть с лева занимала кнопка, а остальное пространство (0.75) 
занимал спиннер. И ета пропорция должна сохранятся.

Точнее можно то мне нужно можно видеть  в атачменте.

Я ето пробовал реализавать GridBagLayout. Но не очен' еффект...

Моя попытка -> 
Код

         setLayout(new GridBagLayout());
        
     gbc.fill = GridBagConstraints.HORIZONTAL;
        
        gbc.gridx = 0;
        gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.LINE_START;
        gbc.fill = GridBagConstraints.BOTH;
        add(button, gbc);
        
        gbc.gridx = 1;
        gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.fill = GridBagConstraints.BOTH;
        add(spinner, gbc);

Автор: fixxer 25.3.2010, 18:23
gbc.weightx = 1;

...
gbc.weightx = 3;

Автор: PashaOvechkin 25.3.2010, 18:50
На первый взгяд кажетсья что ето решние. 
Но на sамом деле ети конфиги делают иное -> 

weightx, weighty
Specifying weights is an art that can have a significant impact on the appearance of the components a GridBagLayout controls. Weights are used to determine how to distribute space among columns (weightx) and among rows (weighty); this is important for specifying resizing behavior.
Unless you specify at least one non-zero value for weightx or weighty, all the components clump together in the center of their container. This is because when the weight is 0.0 (the default), the GridBagLayout puts any extra space between its grid of cells and the edges of the container.

Generally weights are specified with 0.0 and 1.0 as the extremes: the numbers in between are used as necessary. Larger numbers indicate that the component's row or column should get more space. For each column, the weight is related to the highest weightx specified for a component within that column, with each multicolumn component's weight being split somehow between the columns the component is in. Similarly, each row's weight is related to the highest weighty specified for a component within that row. Extra space tends to go toward the rightmost column and bottom row.

Но я решил проблему иначе

Автор: jk1 25.3.2010, 18:59
Добавьте к своему коду для кнопки
Код

gbc.weightx = 0.25;

а для спиннера
Код

gbc.weightx = 0.75;


Не хотел повторяться, просто не успел обновить страницу.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)