上下文:
这是SSCCE的两个快照,用于显示布局的奇怪行为,有或没有手风琴作为GridPane中的单元格,重现这些行为的代码,最后是我问的问题。
良好的渲染,正如预期的那样,BorderPane的“中心”内容是标签:
按钮布局不好,BorderPane的“中心”内容是Accordion:
代码:
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();
}
}
问题:
答案 0 :(得分:1)
您的JavaFX版本是什么?我尝试使用最新版本(Java 8 EAP b88),结果如下: