gpt4 book ai didi

java - 布局 GridPanel BorderPanel 按钮 Accordion

转载 作者:行者123 更新时间:2023-12-01 14:36:09 25 4
gpt4 key购买 nike

上下文:

  • Windows 7 64 位
  • 公共(public) JDK 7“1.7.0_13”版本 1.7.0_13-b20

这是 SSCCE 的两个快照,用于显示布局的奇怪行为,无论是否有 Accordion 作为 GridPane 的单元格,重现这些行为的代码以及最后我提出的问题。

渲染良好,正如预期的那样,BorderPane 的“中心”内容是一个 Label:

Good rendering, as expected

按钮布局错误,BorderPane 的“中心”内容是 Accordion :

Bad layout of the button

代码:

import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.scene.Scene;
import javafx.scene.control.Accordion;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;

public class SSCCE extends Application {

public static final boolean TOO_BIG_BUTTON = true;
// public static final boolean TOO_BIG_BUTTON = false;

public static void main( String[] args ) {
launch( args );
}

@SuppressWarnings("nls")
@Override
public void start( Stage stage ) {
TextField tf = new TextField( "textfield" );
BorderPane bp = new BorderPane();
Label lv = new Label( "BorderPane - Center - Center - Center - Center - Center" );
lv.setPrefHeight( 96.0 );
if( TOO_BIG_BUTTON ) {
Accordion acc = new Accordion();
TitledPane tp = new TitledPane( "Titled pane", lv );
acc.getPanes().add( tp );
acc.setExpandedPane( tp );
stage.setTitle( "SSCCE - too large button" );
bp.setCenter( acc );
}
else {
stage.setTitle( "SSCCE - as expected" );
bp.setCenter( lv );
}
GridPane gp = new GridPane();
Label lbl = new Label( "Label: " );
Button btn = new Button( "button" );
btn.setMaxWidth( Double.MAX_VALUE );
gp.add( lbl, 0, 1 );
gp.add( tf , 1, 1 );
gp.add( btn, 2, 1 );
gp.add( bp , 0, 2, 3, 1 );
GridPane.setHgrow( tf , Priority.ALWAYS );
GridPane.setHgrow( btn, Priority.NEVER );
GridPane.setHalignment( btn, HPos.RIGHT );
stage.setScene( new Scene( gp ));
stage.centerOnScreen();
stage.show();
}
}

问题:

  • 为什么?
  • 如何帮助布局管理器计算按钮的正确尺寸?

编辑Bug entered into JavaFX bug tracking system Jira.

最佳答案

您的 JavaFX 版本是什么?我使用最新版本(Java 8 EAP b88)进行了尝试,结果是这样的:

enter image description here

关于java - 布局 GridPanel BorderPanel 按钮 Accordion ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16472589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com