【问题标题】:How to change float of this button?如何更改此按钮的浮动?
【发布时间】:2014-09-06 08:53:15
【问题描述】:

大家好,

我是新的 Javafx 并试图将此按钮的浮动从当前的 Right side 更改为 Left side.. 怎么做?

我现在只是使用Pane 作为容器。

看看这个截图:

如何做到这一点? ..请帮忙

提前致谢!

已编辑

源代码:

package sample;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.scene.control.TextField;
import javafx.scene.control.Button;

public class Main extends Application {

    @Override
    public void start (Stage primaryStage){
        primaryStage.setTitle("Modern web browser made by Rajendra arora.");
        WebView wv = new WebView();
        wv.setLayoutX(0.0);
        wv.setLayoutY(40.0);
        wv.setPrefHeight(Double.MAX_EXPONENT);
        wv.setPrefWidth(Double.MAX_EXPONENT);
        WebEngine we = wv.getEngine();
        we.load("http://www.google.com/");

        Button btn=new Button("Go");


        TextField tf = new TextField("http://www.google.com/");
        tf.setLayoutX(1.0);
        tf.setPrefWidth(Double.MAX_EXPONENT);
        tf.setPrefHeight(25.0);

        Pane sp = new Pane();
        sp.getChildren().add(tf);
        sp.getChildren().add(btn);
        sp.getChildren().add(wv);

        Scene scene = new Scene(sp, 600, 500);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

【问题讨论】:

  • 你用的是什么布局?
  • 我只是使用 Pane 作为容器 .. 请在我编辑时查看我的代码 ..

标签: java mysql javafx


【解决方案1】:

使用HBox 保存文本字段和按钮,稍后将其添加到Pane

HBox hbox = new HBox();
hbox.getChildren().addAll(tf, btn);
Pane sp = new Pane();
sp.getChildren().add(hbox);
sp.getChildren().add(wv);

【讨论】:

  • 好的,我可以看到文本字段但看不到按钮.. screenshot
猜你喜欢
  • 1970-01-01
  • 2017-06-13
  • 2018-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-27
  • 2020-01-11
  • 1970-01-01
相关资源
最近更新 更多