JavaFX - How to prevent Toolbar from changing width on button state changes

▼魔方 西西 提交于 2019-12-08 05:57:33

问题


I have a problem with TooBar, when one of the included ToggleButtons gain/looses focus or gets checked/unchecked - their visual appearance become slightly bigger / or smaller by a few pixels but the Toolbar adjusts its width accordingly.

When I click on some other UI element - "Objects button" losses focus, becomes smaller and Toolbar width decreases. It's quite annoying that Toolbar size changes all the time. Also, the second button becomes not aligned with first one.

What can be done here to keep all buttons aligned all the time regardless of their current state and have Toolbar width fixed ?

The code for the vertical toolbar is:

<HBox fx:id="leftPanelSwitchPanel">
        <ToolBar orientation="VERTICAL" style="-fx-base: #d1ffd3;">
            <Group>
                <ToggleButton fx:id="objectListPanelSwitch" rotate="-90.0" text="Objects">
                    <graphic>
                        <MaterialIconView glyphName="FORMAT_LIST_BULLETED" />
                    </graphic>
                </ToggleButton>
            </Group>
            <Group>
                <ToggleButton fx:id="objectPropertiesPanelSwitch" rotate="-90.0" text="Properties">
                    <graphic>
                        <MaterialIconView glyphName="SETTINGS_APPLICATIONS" />
                    </graphic>
                </ToggleButton>
            </Group>
        </ToolBar>
    </HBox>

回答1:


You can change focused button/toggle-button css:

.button:focused {
  -fx-background-color: -fx-outer-border, -fx-inner-border, #d5e1f2;
  -fx-background-insets: 0, 1, 2;
  -fx-background-radius: 5, 4, 3;
} 
.toggle-button:focused {
  -fx-background-color: -fx-outer-border, -fx-inner-border, #d5e1f2;
  -fx-background-insets: 0, 1, 2;
  -fx-background-radius: 5, 4, 3;
} 

See for details: How to get rid of focus highlighting in JavaFX



来源:https://stackoverflow.com/questions/43596588/javafx-how-to-prevent-toolbar-from-changing-width-on-button-state-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!