我在组中安排组件时遇到问题, 我正在尝试将这个mybutton和mytextarea以及我的文本域组件放在左边。
它适用于其中三个组件,但当您将第四个组件放在一行中时,所有组件都会向右转。对不起,如果英语不好,
setTranslateX (x);
setTranslateY (y);
不要给我准确的结果, setLayoutx,我认为它不起作用, 这是我的代码。
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);
}
}
任何想法?我将不胜感激。
答案 0 :(得分:1)
以下是如何实现此布局样式的示例。 Tab1显示了使用BorderPane
的示例。 Tab2显示了使用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);
}
}