简体   繁体   English

JavaFX Scene Builder中的“调整大小”按钮

[英]Resizing button in JavaFX Scene Builder

Hope this question has already been asked before, googling has yielded me nothing. 希望以前已经问过这个问题,谷歌搜索对我没有任何帮助。 I've been using Scene Builder to try and code a GUI, but I can't re-size a particular button for some reason. 我一直在使用Scene Builder尝试对GUI进行编码,但是由于某种原因我无法调整特定按钮的大小。 Whenever I try to shrink it, it just snaps back to its regular size. 每当我尝试缩小尺寸时,它都会恢复正常尺寸。 I'm using Ubuntu Linux 12.04, if that makes any difference, and Eclipse. 我正在使用Ubuntu Linux 12.04(如果有任何不同)和Eclipse。 Thanks! 谢谢! 屏幕生成器的截图,带有拒绝缩小的按钮

You are placing your button in a ButtonBar . 您将按钮放置在ButtonBar中 By default, a ButtonBar manages the size of the buttons placed in it. 默认情况下,ButtonBar管理放置在其中的按钮的大小。

By default all buttons are uniformly sized in a ButtonBar, meaning that all buttons take the width of the widest button. 默认情况下,所有按钮在ButtonBar中的大小均一,这意味着所有按钮均采用最宽按钮的宽度。 It is possible to opt-out of this on a per-button basis, [by] calling the setButtonUniformSize(Node, boolean) method with a boolean value of false. 可以按每个按钮选择退出,方法是通过调用布尔值为false的setButtonUniformSize(Node,boolean)方法。

If a button is excluded from uniform sizing, it is both excluded from being resized away from its preferred size, and also excluded from the measuring process, so its size will not influence the maximum size calculated for all buttons in the ButtonBar. 如果将按钮从统一大小调整中排除,则既不会将其调整为超出其首选大小的大小,也不会将其排除在测量过程之外,因此其大小不会影响为ButtonBar中的所有按钮计算的最大大小。

If you want to opt out of uniform sizing, you may need to do that in code as you may not be able to do that graphically just using the SceneBuilder UI. 如果要选择不使用统一大小调整,则可能需要在代码中执行此操作,因为仅使用SceneBuilder UI可能无法以图形方式执行此操作。 Or you may want to use a different container than a ButtonBar for your buttons. 或者您可能想为按钮使用与ButtonBar不同的容器。

Answers to follow-up questions in comments 评论中后续问题的答案

I tried to use the button outside and resize, but it resists getting smaller. 我尝试在外部使用按钮并调整大小,但它无法缩小。

Works for me (SceneBuilder 8 on OS X 9.5). 适用于我(OS X 9.5上的SceneBuilder 8)。

  • Ensure that no ButtonBar is used. 确保不使用ButtonBar。
  • Create a new project in SceneBuilder. 在SceneBuilder中创建一个新项目。
  • Add a StackPane as the root. 添加一个StackPane作为根。
  • Put a button in the StackPane 在StackPane中放置一个按钮
  • Resize the button by dragging it's boundaries in SceneBuilder. 通过在SceneBuilder中拖动按钮的边界来调整按钮的大小。

Does it have something to do with my OS? 它与我的操作系统有关吗?

High unlikely. 高可能性不大。 If it did, it would be an OS specific bug. 如果确实如此,那将是特定于操作系统的错误。 Functions like this in JavaFX should work identically across operating systems. JavaFX中的此类功能在整个操作系统上应完全相同。

I'm following at code.makery.ch/library/javafx-8-tutorial/part1, and the buttons show up as a different size: i.imgur.com/gCsbTtX.png 我在code.makery.ch/library/javafx-8-tutorial/part1中关注,并且按钮显示为不同的大小:i.imgur.com/gCsbTtX.png

Size of controls in JavaFX are based upon the size of the font used for those controls. JavaFX中控件的大小取决于用于这些控件的字体的大小。 JavaFX uses the default system font, unless additional styling is provided. JavaFX使用默认的系统字体,除非提供其他样式。 The size of the default system font varies depending on the OS and the system settings in the OS. 默认系统字体的大小取决于操作系统和操作系统中的系统设置。 It could be this variation that you are detecting. 您正在检测的可能就是这种变化。

Do I need to develop on Windows instead or something? 我是否需要在Windows上进行开发?

No, that should not be the case. 不,事实并非如此。

You can simply change the padding of the button you need to change. 您可以简单地更改需要更改的按钮的填充。 If you want to shrink it, then try negative numbers 如果要缩小,请尝试负数

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

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