導航:首頁 > 編程語言 > 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相關的資料

熱點內容
word刪除章節附註分隔符 瀏覽:773
公告質疑需要哪些文件 瀏覽:608
資料庫模型是干什麼的 瀏覽:404
win10的驅動怎麼安裝驅動 瀏覽:320
word文件水印怎麼取消 瀏覽:443
rhel6的鏡像文件在哪裡下載 瀏覽:571
成功正能量微信頭像 瀏覽:848
wps表格如何恢復數據 瀏覽:264
linuxc靜態庫創建 瀏覽:838
u盤有微信文件但微信恢復不了 瀏覽:585
蘋果的網站數據是什麼 瀏覽:22
ps滾字教程 瀏覽:237
win7網路鄰居如何保存ftp 瀏覽:186
安卓客戶端代理伺服器 瀏覽:572
編程用蘋果 瀏覽:659
51虛擬機的文件管理在哪裡 瀏覽:13
win10系統有沒有便簽 瀏覽:722
java引用傳遞和值傳遞 瀏覽:109
oracle下載安裝教程 瀏覽:854
php篩選資料庫 瀏覽:830

友情鏈接