2017-04-24 56 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