在Javafx中排列组件

在Javafx中排列组件,javafx,Javafx,我在组中安排组件时遇到问题, 我试着把这个mybutton、mytextarea和我的textfield组件放在左边 它适用于其中三个组件,但当您将第四个组件放在一行中时,所有组件都会向右旋转。对不起,如果英语不好 setTranslateX (x); setTranslateY (y); 不要给我准确的结果, setLayoutx,y我想它不起作用, 这是我的密码 import javafx.application.Application; import javafx.collections

我在组中安排组件时遇到问题, 我试着把这个mybutton、mytextarea和我的textfield组件放在左边

它适用于其中三个组件,但当您将第四个组件放在一行中时,所有组件都会向右旋转。对不起,如果英语不好

setTranslateX (x);
setTranslateY (y);
不要给我准确的结果, setLayoutx,y我想它不起作用, 这是我的密码

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import tender.schedule.tm.Control.MyButton;
import tender.schedule.tm.Control.MyTabed;
import tender.schedule.tm.Control.MyTextArea;
import tender.schedule.tm.Control.MyTextField;

public class TenderScheduleTM extends Application {

@Override
public void start(Stage primaryStage) {
    Group Tender = new Group();
    ObservableList ob = Tender.getChildren();

                                 //x      y
    MyTextArea mta =new MyTextArea(880, 110,300,100,"المادة");
    ob.add(mta);
    //mta.setLayoutX(800);
    //mta.setLayoutY(10);
                                     //x    y
    MyTextField mtf1 =new MyTextField(880, 230, 300, 40,"العدد");
    ob.add(mtf1);
    //mtf1.setLayoutX(890);
    //mtf1.setLayoutY(10);
                                     //x    y
    MyTextField mtf2 =new MyTextField(880, 280, 300, 40, "السعر");
    ob.add(mtf2);
    //mtf2.setLayoutX(890);
    //mtf2.setLayoutY(10);

    Image listimg=new Image(getClass().getResourceAsStream("/images/list.png"));
                             //x    y
    MyButton mb1=new MyButton(1150, 0, 30, 30, new ImageView(listimg));
    //mb1.setLayoutX(1200);
    //mb1.setLayoutY(80);
    ob.add(mb1);

    MyTabed mb =new MyTabed();
    Tab t1 =new Tab();

    t1.setContent(Tender);
    mb.addTab("الجدول", t1);
    mb.addTab("المخطط", new Tab());

    Scene scene = new Scene(mb,1200,600);
    primaryStage.setTitle("Tender Schedule");
    primaryStage.setScene(scene);
    primaryStage.show();
}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}

}
明白了吗


有什么想法吗?我将不胜感激。

以下是如何实现这种布局风格的示例。表1显示了使用
BorderPane
的示例。表2显示了使用HBox的示例

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class TestingGrounds extends Application
{

    @Override
    public void start(Stage primaryStage) throws Exception
    {
        //Example using BorderPane
        TextField textField1 = new TextField("textfield 1");
        TextArea textArea1 = new TextArea("textArea 1");
        TextArea textArea1b = new TextArea("TextArea 1b");
        Button btn1 = new Button("btn 1");
        VBox vBoxLeftRootTab1 = new VBox(textField1, textArea1, textArea1b, btn1);
        BorderPane borderPaneTab1Root = new BorderPane();
        borderPaneTab1Root.setLeft(vBoxLeftRootTab1);
        //You should probably set the Center and/or Right Node of the BorderPane
        Tab tab1 = new Tab("tab1");
        tab1.setContent(borderPaneTab1Root);

        //Example using HBox
        TextField textField2 = new TextField("textfield 2");
        TextArea textArea2 = new TextArea("textArea 2");
        TextArea textArea2b = new TextArea("TextArea 2b");
        Button btn2 = new Button("btn 2");
        VBox vBoxLeftRootTab2 = new VBox(textField2, textArea2, textArea2b, btn2);        
        //You may want to add more another layout Node in the HBox that will be to the right of what's on the left. 
        HBox hBoxTab2Root = new HBox(vBoxLeftRootTab2);
        Tab tab2 = new Tab("tab2");
        tab2.setContent(hBoxTab2Root);

        TabPane tabPane = new TabPane();
        tabPane.getTabs().addAll(tab1, tab2);

        StackPane root = new StackPane(tabPane);

        Scene scene = new Scene(root, 750, 500);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

接受其子节点边界的并集,因此组本身将被定位,而不管它包含的节点的布局坐标如何。像这样“用手”定位所有东西通常是个坏主意。您应该使用特定的(或它们的组合)来提供所需的布局(类似于
VBox
,具有适当的
alignment
设置和
space
应该足够了)。不要尝试手动设置
节点。适当地使用
布局
节点
,以获得所需的结果。您应该从
BorderPane
HBox
开始。只是猜猜而已。谢谢你,这帮了我的忙。