导航:首页 > 编程语言 > javafxgridpane

javafxgridpane

发布时间:2023-02-09 21:36:29

javafx怎么通过表格组件做一个课程表的界面

word中插入表格后“表格”“绘制斜线表头”选择样式二并在右边分别输入标题名称后确定即可

② javafx 如何让ComboBox铺满GridPane的整列

试试GridPane的这个方法:
public static void setHgrow(Node child,
Priority value)

Sets the horizontal grow priority for the child when contained by a gridpane.
If set, the gridpane will use the priority to allocate the child additional
horizontal space if the gridpane is resized larger than it's preferred width.
Setting the value to null will remove the constraint.

Parameters:
child - the child of a gridpane
value - the horizontal grow priority for the child

③ 求大佬帮帮忙用java写这样一个界面。

④ javafx 如何让ComboBox充满GridPane的整列

GridPane 类有用于 GridPane 布局的静态 setHgrow() 和 setVgrow() 方法。
静态 setHgrow() 方法传递 Priority.ALWAYS 参数意味着我们希望该节点占用所有可用的水平空间,并与水平增长限制为 ALWAYS 的其他节点共享此空间。Priority 枚举中的其他常量为 SOMETIMES 和 NEVER,可用于进一步控制增长行为。

⑤ JavaFXGridPane间隔可以设置颜色吗

GridPane通常用于布局:第一列上的只读标签的输入表单和第二列上的输入字段。

GridPane可以在行,列或单元格级别指定约束。
例如,我们可以设置包含输入文本字段的第二列,以在窗口调整大小时调整大小。

示例

以下代码演示使用GridPane布局的简单表单应用程序。它有以下布局。

+------------------------+
| [label ] [ field ] |
| [label ] [ field ] |
| [ button ] |
+------------------------+
Java
完整的代码实现如下所示 -

import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

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

@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 380, 150, Color.WHITE);
// @ w WW .yII b a I .c O m
GridPane gridpane = new GridPane();
gridpane.setPadding(new Insets(5));
gridpane.setHgap(5);
gridpane.setVgap(5);
ColumnConstraints column1 = new ColumnConstraints(100);
ColumnConstraints column2 = new ColumnConstraints(50, 150, 300);
column2.setHgrow(Priority.ALWAYS);
gridpane.getColumnConstraints().addAll(column1, column2);

Label fNameLbl = new Label("First Name");
TextField fNameFld = new TextField();
Label lNameLbl = new Label("Last Name");
TextField lNameFld = new TextField();

Button saveButt = new Button("Save");

// First name label
GridPane.setHalignment(fNameLbl, HPos.RIGHT);
gridpane.add(fNameLbl, 0, 0);

// Last name label
GridPane.setHalignment(lNameLbl, HPos.RIGHT);
gridpane.add(lNameLbl, 0, 1);

// First name field
GridPane.setHalignment(fNameFld, HPos.LEFT);
gridpane.add(fNameFld, 1, 0);

// Last name field
GridPane.setHalignment(lNameFld, HPos.LEFT);
gridpane.add(lNameFld, 1, 1);

// Save button
GridPane.setHalignment(saveButt, HPos.RIGHT);
gridpane.add(saveButt, 1, 2);

root.setCenter(gridpane);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Java
上面的代码生成以下结果。

示例2

以下是一个实现登录窗口的代码 -

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Main extends Application {

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

@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX Welcome");
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));

Text scenetitle = new Text("Welcome");
scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
grid.add(scenetitle, 0, 0, 2, 1);

Label userName = new Label("User Name:");
grid.add(userName, 0, 1);

TextField userTextField = new TextField();
grid.add(userTextField, 1, 1);

Label pw = new Label("Password:");
grid.add(pw, 0, 2);

PasswordField pwBox = new PasswordField();
grid.add(pwBox, 1, 2);

Button btn = new Button("Sign in");
HBox hbBtn = new HBox(10);
hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
hbBtn.getChildren().add(btn);
grid.add(hbBtn, 1, 4);

final Text actiontarget = new Text();
grid.add(actiontarget, 1, 6);

btn.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent e) {
actiontarget.setFill(Color.FIREBRICK);
actiontarget.setText("Sign in button pressed");
}
});

Scene scene = new Scene(grid, 300, 275);
primaryStage.setScene(scene);
primaryStage.show();
}
}

⑥ javafx窗体面板位置

点击 ImageView 调整窗口。
Javafx几种典型的布局是FlowPane面板它采用的布局策略是,按照控件的添加次序按个摆放,按照从上到下,从左到右的次序摆放,当窗口的大小发生变化后,场景的大小也自动跟着变化,面板的大小也跟着变化,并且会重新计算各个控件的位置,重新摆放各个控件的位置,GridPane面板它采用的布局策略是,将整个面板划分为若干个格子,每个格子的大小是一样的,每个格子中可以放置一个控件,类似于表格的方式。

⑦ Javafx计算器的问题,我想知道那个显示框是用什么方法,我用textfield的话好像会影响我的

importjavafx.application.Application;
importjavafx.geometry.Insets;
importjavafx.geometry.Pos;
importjavafx.scene.Scene;
importjavafx.scene.control.Button;
importjavafx.scene.control.TextField;
importjavafx.scene.layout.GridPane;
importjavafx.scene.text.Font;
importjavafx.scene.text.FontWeight;
importjavafx.stage.Stage;

{
privatestaticfinalStringstr="123+456-789×C0.÷";

publicstaticvoidmain(String[]args){
launch(args);
}

@Override
publicvoidstart(StageprimaryStage)throwsException{

GridPaneroot=newGridPane();
root.setAlignment(Pos.CENTER);
root.setPadding(newInsets(15));
root.setHgap(10);
root.setVgap(10);
Scenescene=newScene(root,300,350);
TextFieldtf=newTextField();
tf.setPrefHeight(50);//设置文本框的最佳高度为50
tf.setFont(Font.font(java.awt.Font.MONOSPACED,FontWeight.BOLD,18));//字体设置
root.add(tf,0,0,3,1);//跨三列,跨一行

Buttonbtn1=newButton("=");
btn1.setPrefSize(50,50);//设置按钮的最佳宽高
root.add(btn1,3,0);
for(inti=0;i<str.length();i++){
Buttonbtn=newButton(str.charAt(i)+"");
btn.setPrefSize(50,50);
root.add(btn,i%4,i/4+1);//计算出列和行,并添加到GridPane上去
}
primaryStage.setScene(scene);
primaryStage.setTitle("Calculator");
primaryStage.show();
}

}

⑧ javafx里的gridpane怎么给定行和列来删除一个节点

GridPane 类有用于 GridPane 布局的静态 setHgrow() 和 setVgrow() 方法。 静态 setHgrow() 方法传递 Priority.ALWAYS 参数意味着我们希望该节点占用所有可用的水平空间,并与水平增长限制为 ALWAYS 的其他节点共享此空间。

⑨ javafx怎么实现页面的跳转

1. 后台
public class Check {
public static boolean checkreturn(String account,String password){
boolean checkbool = false;
if("account".equals(account)&&"password".equals(password)){
checkbool = true;
}
return checkbool;
}
}

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;

public class LoginController implements Initializable {
@FXML private TextField account;
@FXML private PasswordField password;
private FXMLTest application;

public void setApp(FXMLTest application){
this.application = application;
}
@FXML
public void LOGIN_M(ActionEvent event) {
application.userlogin(account.getText(), password.getText());
}

@FXML
private void CLEAR_M(ActionEvent event) {
account.setText(null);
password.setText(null);
}

@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;

public class MainController implements Initializable{
private FXMLTest application;

public void setApp(FXMLTest application){
this.application = application;
}

@FXML
private void OUT_M(ActionEvent event) {
application.useroutmain();
}

@Override
public void initialize(URL url, ResourceBundle rb) {

}

}

import check.Check;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class FXMLTest extends Application {
private Stage stage;
private final double MINIMUM_WINDOW_WIDTH = 400.0;
private final double MINIMUM_WINDOW_HEIGHT = 250.0;

@Override
public void start(Stage primaryStage) throws Exception {
stage = primaryStage;
stage.setTitle("FXML Login Sample");
stage.setMinWidth(MINIMUM_WINDOW_WIDTH);
stage.setMinHeight(MINIMUM_WINDOW_HEIGHT);
gotologin();
stage.show();
}
public void gotologin(){
try {
LoginController login = (LoginController) replaceSceneContent("FXML_LOGIN.fxml");
login.setApp(this);
} catch (Exception ex) {
Logger.getLogger(FXMLTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void gotomain(){
try {
MainController main = (MainController) replaceSceneContent("FXML_MAIN.fxml");
main.setApp(this);
} catch (Exception ex) {
Logger.getLogger(FXMLTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void userlogin(String account,String password){
if(Check.checkreturn(account,password)){
gotomain();
}
}
public void useroutmain(){
gotologin();
}
private Initializable replaceSceneContent(String fxml) throws Exception {
FXMLLoader loader = new FXMLLoader();
InputStream in = FXMLTest.class.getResourceAsStream(fxml);
loader.setBuilderFactory(new JavaFXBuilderFactory());
loader.setLocation(FXMLTest.class.getResource(fxml));
AnchorPane page;
try {
page = (AnchorPane) loader.load(in);
} finally {
in.close();
}
Scene scene = new Scene(page, 800, 600);
stage.setScene(scene);
stage.sizeToScene();
return (Initializable) loader.getController();
}
public static void main(String[] args) {
launch(args);
}
}
2. xml配置

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="400.0"
xmlns:fx="http://javafx.com/fxml" fx:controller="fxmltest.LoginController">
<children>
<VBox layoutX="3.0" layoutY="0.0" prefHeight="250.0" prefWidth="390.0" spacing="20.0">
<children>
<HBox minHeight="37.0" prefHeight="37.0" prefWidth="411.0">
<children>
<Label text="登陆界面">
<effect>
<DropShadow height="7.845238095238096" radius="4.1815476190476195" width="10.880952380952381" />
</effect>
<font>
<Font name="System Bold" size="30.0" />
</font>
<HBox.margin>
<Insets left="140.0" />
</HBox.margin>
</Label>
</children>
</HBox>
<GridPane alignment="TOP_RIGHT" prefWidth="380.0">
<children>
<Label alignment="TOP_RIGHT" text="Account" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="0">
<effect>
<DropShadow blurType="TWO_PASS_BOX" height="7.845238095238096" radius="3.675595238095238" width="8.857142857142858" />
</effect>
<font>
<Font size="25.0" fx:id="x1" />
</font>
<GridPane.margin>
<Insets right="8.0" fx:id="x2" />
</GridPane.margin>
</Label>
<Label font="$x1" text="password" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.margin="$x2" GridPane.rowIndex="1">
<effect>
<DropShadow blurType="TWO_PASS_BOX" height="7.845238095238094" radius="3.6755952380952372" width="8.857142857142854" />
</effect>
</Label>
<TextField fx:id="account" prefHeight="26.0" prefWidth="268.0" promptText="please input your account" GridPane.columnIndex="1" GridPane.rowIndex="0" />
<PasswordField fx:id="password" prefWidth="223.0" promptText="please input your password" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Button id="btn_login" mnemonicParsing="false" onAction="#LOGIN_M" prefWidth="80.0" text="登陆" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="2">
<effect>
<DropShadow />
</effect>
<GridPane.margin>
<Insets top="15.0" />
</GridPane.margin>
</Button>
<Button id="btn_clear" mnemonicParsing="false" onAction="#CLEAR_M" prefWidth="80.0" text="清除" GridPane.columnIndex="1" GridPane.rowIndex="2">
<effect>
<DropShadow />
</effect>
<GridPane.margin>
<Insets left="80.0" top="15.0" />
</GridPane.margin>
</Button>
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="205.0" minWidth="10.0" prefWidth="147.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="318.0" minWidth="10.0" prefWidth="243.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
<padding>
<Insets top="30.0" />
</padding>
</VBox>
</children>
</AnchorPane>

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"
xmlns:fx="http://javafx.com/fxml" fx:controller="fxmltest.MainController">
<children>
<Hyperlink layoutX="86.0" layoutY="111.0" text="退出登录!" onAction="#OUT_M">
<font>
<Font size="45.0" />
</font>
</Hyperlink>
</children>
</AnchorPane>

⑩ 在GridPane怎么添加TextField和Label

我也遇到了这个问题,然后我显式地写了

importjavafx.scene.control.Button;
importjavafx.scene.control.TextField;
importjavafx.scene.control.Label;

就不报错了

阅读全文

与javafxgridpane相关的资料

热点内容
编程用苹果 浏览:659
51虚拟机的文件管理在哪里 浏览:13
win10系统有没有便签 浏览:722
java引用传递和值传递 浏览:109
oracle下载安装教程 浏览:854
php筛选数据库 浏览:830
怎么用手机看wlan密码 浏览:745
奥维地图导入的文件在哪里 浏览:364
sdltrados2014教程 浏览:43
培训制度文件在哪里找 浏览:601
勒索病毒防疫工具 浏览:861
win10c不能打开 浏览:375
xfplay影音先锋苹果版 浏览:597
两个文件打开两个word 浏览:921
苹果6s桌面图标轻微抖动 浏览:326
如何删除手机中看不见的临时文件 浏览:469
安卓412原生锁屏apk 浏览:464
书加加缓存文件在哪里 浏览:635
dock是word文件吗 浏览:267
社保公司新办去哪个网站下载资料 浏览:640

友情链接