JavaFX:在ButtonBar中对齐按钮(使用SceneBuilder或fxml) [英] JavaFX: Align Buttons inside ButtonBar (using SceneBuilder or fxml)

查看:391
本文介绍了JavaFX:在ButtonBar中对齐按钮(使用SceneBuilder或fxml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaFX



来自文档我我已经知道如何在java-source-code中实现这个目标:

  ButtonBar.setButtonData(newButton,ButtonData.LEFT); 



但是



我想知道如何实现这一点而不必在我的java文件中写这个但是我如何使用SceneBuilder或相应的fxml文件来实现这一点。



我的.fxml文件目前如下所示:

 < ButtonBar> 
< buttons>
< Button text =New/>
<按钮文字=保存/>
< / buttons>
< / ButtonBar>

*我在Windows

** 这个答案不是我想要的,因为他正在使用ToolBar,但我想知道如何使用ButtonBar(并且他的方法不适用于ButtonBar)

解决方案

经过一些试验和错误我发现至少有一种方法可以通过.fxml文件直接进行:



你可以用<$ c分配Button元素$ c> ButtonBar.buttonData 属性然后为它们赋值。

 < ButtonBar> 
< buttons>
< Button text =NewButtonBar.buttonData =LEFT/>
< Button text =SaveButtonBar.buttonData =RIGHT/>
< / buttons>
< / ButtonBar>

ButtonBar.ButtonData枚举非常简单。所以我用LEFT和RIGHT枚举值找到了我的问题的解决方案。



STILL



如果有人知道/在SceneBuilder中直接找到如何做到这一点,我将不胜感激!


I have a JavaFX ButtonBar with two Buttons (created via SceneBuilder).

I want one of the buttons to be left-aligned and the other right-aligned. (see screenshot)

From the docs I already know how I could achieve this inside the java-source-code:

ButtonBar.setButtonData(newButton, ButtonData.LEFT);

BUT

I want to know how to achieve this WITHOUT having to write this inside my java-files but
how I can achieve this using just SceneBuilder or the corresponding fxml file.

My .fxml file currently looks like this:

<ButtonBar>
  <buttons>
    <Button text="New" />
    <Button text="Save" />
  </buttons>
</ButtonBar>

* I'm on Windows
** This answer is not what I want, because he is using a ToolBar, but I want to know how to do this with a ButtonBar (and his approach does not work for the ButtonBar)

解决方案

After some Trial and Error I found at least a way to do it directly via the .fxml-file:

You can assign the Button elements with ButtonBar.buttonData attributes and then assign a value to them.

<ButtonBar>
  <buttons>
    <Button text="New" ButtonBar.buttonData="LEFT" />
    <Button text="Save" ButtonBar.buttonData="RIGHT" />
  </buttons>
</ButtonBar>

The docs for the ButtonBar.ButtonData enum are pretty straighforward. So I found the solution to my problem with the "LEFT" and "RIGHT" enum values.

STILL

If anyone knows/finds out how to do this directly in SceneBuilder, I would be grateful!

这篇关于JavaFX:在ButtonBar中对齐按钮(使用SceneBuilder或fxml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆