简体   繁体   English

ButtonBar:相同的按钮高度

[英]ButtonBar: Same Button Height

I have an app with a very dynamic button bar of about one to twelve or so buttons that change text and functionality with the current screen and/or selected record.我有一个应用程序,它有一个非常动态的按钮栏,大约有 1 到 12 个按钮,可以根据当前屏幕和/或所选记录更改文本和功能。 I'm using a ButtonBar to display them.我正在使用 ButtonBar 来显示它们。

The buttons in the bar wrap their text, when it's too large, as they should, but I end up with this dumb situation:当文本太大时,栏中的按钮将它们的文本包裹起来,这是应该的,但我最终遇到了这种愚蠢的情况:

在此处输入图片说明

The buttons are different heights!按钮高度不同! I would like the ButtonBar to give me well-regulated buttons, like so:我希望 ButtonBar 为我提供规范的按钮,如下所示:

在此处输入图片说明

I can cheat, after a fashion by splitting each button up into three lines.我可以通过将每个按钮分成三行来作弊。 This creates a situation where the small buttons are swimming in space:这会造成小按钮在空间中游动的情况:

在此处输入图片说明

(If I use two lines, I get less wasted space, which is good, but the single-line text ceases to be centered, which also looks awful.) (如果我使用两行,我会减少浪费的空间,这很好,但单行文本不再居中,这看起来也很糟糕。)

Right now, the only thing I can think of to do is, after the bar renders, scan across all the buttons for the tallest one, and then adjust every other button accordingly.现在,我唯一能想到的就是,在条形渲染后,扫描所有按钮以找到最高的按钮,然后相应地调整每个其他按钮。 The ButtonBar does with width, which is good (but actually probably less desirable than all the buttons being the same height). ButtonBar 有宽度,这很好(但实际上可能不如所有按钮的高度相同)。 The misleadingly named "UniformButtonSize" does this.误导性命名的“UniformButtonSize”就是这样做的。

I'm wondering if I can do this with CSS somehow, maybe setting button heights as a percentage.我想知道我是否可以用 CSS 以某种方式做到这一点,也许可以将按钮高度设置为百分比。 Any suggestions would be appreciated!任何建议,将不胜感激!

This is a little tacky but it seems to do the trick:这有点俗气,但似乎可以解决问题:

    public void adjustButtons() {
        var tallest = 0.0;
        for (Node n : buttonBar.getButtons()) {
            var ht = ((Button) n).getHeight();
            if (tallest < ht) tallest = ht;
        }
        for (Node n : buttonBar.getButtons()) {
            ((Button) n).setMinHeight(tallest);
        }
    }

So, any time the buttons in the button bar change, you fire this, it finds the tallest button, then it goes and sets all the buttons to that height.因此,每当按钮栏中的按钮发生变化时,您都会触发它,它会找到最高的按钮,然后将所有按钮设置为该高度。

Comments?注释?

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

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