简体   繁体   English

如何使用jgoodies表单最大化组件高度

[英]how to maximise component height using jgoodies forms

Noob question : I have the following Forms layout (please excuse the JRuby syntax). Noob问题 :我有以下表单布局(请原谅JRuby语法)。 I'd like all three buttons to have their heights stretched to fill the available space. 我希望所有三个按钮都能将其高度拉伸以填充可用空间。 but only button 3 does so. 但只有按钮3才这样做。

require 'java'
require './lib/jgoodies-common-1.2.1.jar'
require './lib/jgoodies-forms-1.4.2.jar'

java_import javax.swing.JButton
java_import javax.swing.JFrame

java_import com.jgoodies.forms.layout.CellConstraints
java_import com.jgoodies.forms.layout.FormLayout

class Foo < JFrame
  def initialize
    super
    cc = CellConstraints.new

    layout = FormLayout.new(
      "10dlu, pref:grow, 10dlu, pref:grow, 10dlu",
      "10dlu, pref:grow, 10dlu, pref:grow, 10dlu"
    )
    layout.setRowGroups([[2, 4]])
    layout.setColumnGroups([[2, 4]])

    self.setLayout(layout)

    self.add(JButton.new("button 1"), cc.xy(2, 2))
    self.add(JButton.new("button 2"), cc.xy(2, 4))
    self.add(JButton.new("button 3"), cc.xywh(4, 2, 1, 3))

    self.pack
    self.setVisible(true)
    self.toFront
  end
end

Foo.new

Tips and pointers appreciated. 提示和指示赞赏。

--Ben --Ben

Tell the rowSpec to fill the height: 告诉rowSpec填充高度:

    FormLayout layout = new FormLayout(
            "10dlu, pref:grow, 10dlu, pref:grow, 10dlu",
            "10dlu, fill:pref:grow, 10dlu, fill:pref:grow, 10dlu"
            );

Technically, that's explicitly overruling the "alignment" of the row, which by default is CENTER. 从技术上讲,这明确地覆盖了行的“对齐”,默认情况下是CENTER。 For columns, the default alignment is FILL (so no overrule needed if you want the stretch horizontally). 对于列,默认对齐方式为FILL(因此,如果要水平拉伸,则不需要覆盖)。 The reason the third button appears to magi-stretching vertically is that it is spanning two content rows: not much else it can align to then fill (as far as I remember, didn't check the details) 第三个按钮看起来垂直拉伸的原因是它跨越了两个内容行:它可以对齐然后填充的其他内容(据我记忆,没有检查细节)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM