2017-04-24 92 views
1

我有一个问题,商工具栏,当包含的ToggleButtons一个增益/失去重点或被选中/取消 - 他们的视觉外观变得稍大/或小由几个像素,但工具栏相应地调整其宽度。JavaFX的 - 如何防止工具栏的按钮状态改变宽度改变

Focused Objects button

当我点击一些其他UI元素 - “对象按钮”损失集中,变得更小和工具栏的宽度减小。工具栏大小始终在变化,这非常烦人。另外,第二个按钮与第一个按钮不一致。

有什么可以在这里完成,以保持对齐所有的时间所有的按钮,无论其当前状态,并有工具栏的宽度固定的吗?

为垂直工具栏的代码是:

<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> 
+0

哦,您使用了与我的解决方案相同的技术:[JavaFX:how to m ake一个适当的垂直工具栏?](http://stackoverflow.com/questions/24774112/javafx-how-to-make-a-proper-vertical-toolbar)该解决方案目前不完美;-) – jewelsea

+0

这是正确的... :) – ievgen

+0

我更新了原始解决方案以解决焦点移动问题。 – jewelsea

回答

2

你可以改变焦点的按钮/切换按钮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; 
} 

Sample button without focused border

详情请参见:How to get rid of focus highlighting in JavaFX

+0

我不能接受这个答案,因为您提供的解决方案对于Windows的外观和模式看起来不自然,但我已经标记为有用,因为它提供了寻找解决方案的正确方向。 Jewelsea我认为提供了更多的防弹解决方案,谢谢! – ievgen

+0

通过说非自然我的意思是说解决方案应该跨平台适用 – ievgen