【发布时间】:2021-08-28 07:36:17
【问题描述】:
这可能是一个微不足道的问题,但到目前为止我无法找到解决方案。
如果您创建一个带有较长单词作为文本的按钮,让我们说“Überspringen”(跳过的德语单词),JavaFx 会自动将文本截断为“Übersprin”+EllipsisString。 Button skipButton = new Button("\u00dcberspringen");
是否有避免截断的简单解决方案?我只能硬编码一个新的尺寸,但在 Swing 中,按钮尺寸是自动调整的。
我已经尝试过setWrapText(true),但没用,我想是因为没有空格。
编辑
这个最小的、可重现的示例显示了我的问题:public class ButtonTest extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception
{
Scene scene = new Scene(getBottomPanel(),600,50);
primaryStage.setScene(scene);
primaryStage.show();
}
private AnchorPane getBottomPanel()
{
HBox infraBox = new HBox(5);
infraBox.setAlignment(Pos.CENTER);
infraBox.getChildren().add(new Label("Input (manuell):"));
infraBox.getChildren().add(new TextField());
Button shortButton = new Button("OK");
Button longButton = new Button("\u00dcberspringen");
ButtonBar buttonBar = new ButtonBar();
buttonBar.getButtons().addAll(shortButton, longButton);
AnchorPane bottomPanel = new AnchorPane(infraBox, buttonBar);
bottomPanel.setPadding(new Insets(5));
AnchorPane.setLeftAnchor(infraBox, 0.0);
AnchorPane.setRightAnchor(buttonBar, 5.0);
return bottomPanel;
}
}
【问题讨论】:
-
应该自动工作,因此您的设置中可能有些地方不太正确(确保使用适当的布局)或者您遇到了错误 :) 不管是什么原因,与往常一样的程序:@987654322 @ 必填。
-
@kleopatra 谢谢!这个怎么样?
-
hmm ..worksforme(fx17-dev,未检查早期版本)
-
这也适用于我,JavaFX 15.0.1。
-
啊 .. 是的,我在 fx8 中也看到了它 - 看起来像一些同时修复的问题(在 fx11 中还可以)。您可能会考虑升级到更新的版本(当前是 fx16,许多错误修复已向后移植到 fx11)。