Java 边框窗格重叠内容
我有子网格窗格,我想如果文本将增加,那么文本应该增加 不是进入网格外窗格,而是滚动窗格,我不想看到框外的苹果文本Java 边框窗格重叠内容,java,javafx,Java,Javafx,我有子网格窗格,我想如果文本将增加,那么文本应该增加 不是进入网格外窗格,而是滚动窗格,我不想看到框外的苹果文本 @Override public void start(Stage primaryStage) throws Exception { String border = "-fx-border-color:red;"; Text title=new Text("Machin"); GridPane topLeft=new GridPane();
@Override
public void start(Stage primaryStage) throws Exception {
String border = "-fx-border-color:red;";
Text title=new Text("Machin");
GridPane topLeft=new GridPane();
topLeft.setMinSize(80, 5);
topLeft.setMaxSize(80, 80);
topLeft.setStyle(border);
topLeft.add(title, 0, 0);
for(int i=1;i<=15;i++) {
topLeft.add(new Text("Apple"), 0,i);
}
GridPane root = new GridPane();
root.setAlignment(Pos.CENTER);
root.setHgap(20);
root.setVgap(20);
root.add(topLeft, 0, 0);
BorderPane borderPane = new BorderPane();
borderPane.setTop(new Label("Header"));
borderPane.setCenter(root);
borderPane.setBottom(new Label("Buttom"));
primaryStage.setScene(new Scene(borderPane, 600, 400));
primaryStage.show();
}
@覆盖
public void start(Stage primaryStage)引发异常{
字符串边框=“-fx边框颜色:红色;”;
文本标题=新文本(“机器”);
GridPane topLeft=新建GridPane();
左上角。设置大小(80,5);
左上角.setMaxSize(80,80);
左上角。设置样式(边框);
添加(标题,0,0);
对于(int i=1;i您可以使用一些更复杂的控件(如或)来封装您的内容,而不是使用布局窗格(如)。这些控件具有内置滚动条,当控件的内容大于可查看区域时,滚动条将显示出来。查看链接教程以评估这些其他控件是否适用于您r应用程序
如果希望保留GridPane
,则可以将GridPane
包装在中,以允许GridPane
的内容在达到特定大小时滚动,如以下示例中所示:
导入javafx.application.application;
导入javafx.scene.scene;
导入javafx.scene.control.*;
导入javafx.scene.layout.*;
导入javafx.scene.text.text;
导入javafx.stage.stage;
公共类ScrollingGrid扩展了应用程序{
@凌驾
public void start(Stage primaryStage)引发异常{
字符串边框=“-fx边框颜色:红色;”;
文本标题=新文本(“机器”);
GridPane appleGrid=新建GridPane();
appleGrid.setMinSize(80,5);
appleGrid.setStyle(边框);
add(title,0,0);
对于(int i=1;i您可以使用一些更复杂的控件(如或)来封装您的内容,而不是使用布局窗格(如)。这些控件具有内置滚动条,当控件的内容大于可查看区域时,滚动条将显示出来。查看链接教程以评估这些其他控件是否适用于你的申请
如果希望保留GridPane
,则可以将GridPane
包装在中,以允许GridPane
的内容在达到特定大小时滚动,如以下示例中所示:
导入javafx.application.application;
导入javafx.scene.scene;
导入javafx.scene.control.*;
导入javafx.scene.layout.*;
导入javafx.scene.text.text;
导入javafx.stage.stage;
公共类ScrollingGrid扩展了应用程序{
@凌驾
public void start(Stage primaryStage)引发异常{
字符串边框=“-fx边框颜色:红色;”;
文本标题=新文本(“机器”);
GridPane appleGrid=新建GridPane();
appleGrid.setMinSize(80,5);
appleGrid.setStyle(边框);
add(title,0,0);
对于(int i=1;i您可能会考虑<代码> ListVIEW < /Cord> > <代码> GrdPANE< /代码>。您可以考虑<代码> ListVIEW > <代码> GRIDPANE<代码>。
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class ScrollingGrid extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
String border = "-fx-border-color:red;";
Text title = new Text("Machin");
GridPane appleGrid = new GridPane();
appleGrid.setMinSize(80, 5);
appleGrid.setStyle(border);
appleGrid.add(title, 0, 0);
for (int i = 1; i <= 15; i++) {
appleGrid.add(new Text("Apple"), 0, i);
}
ScrollPane scrollPane = new ScrollPane(appleGrid);
scrollPane.setPrefViewportWidth(80);
scrollPane.setPrefViewportHeight(80);
scrollPane.setMaxSize(ScrollPane.USE_PREF_SIZE, ScrollPane.USE_PREF_SIZE);
BorderPane borderPane = new BorderPane();
borderPane.setTop(new Label("Header"));
borderPane.setCenter(scrollPane);
borderPane.setBottom(new Label("Bottom"));
primaryStage.setScene(new Scene(borderPane, 600, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}