Codes:
package javafxtemplate1;
import java.sql.SQLException;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class JavaFXTemplate1 extends Application {
@Override
public void start(Stage primaryStage)throws SQLException {
StackPane root = new StackPane();
HBox hbox = new HBox(30);
//
VBox vbox1 = new VBox(10);
Label label1 = new Label("Label1");
//label1.setStyle("-fx-background-color:
//slateblue; -fx-text-fill: white;");
//OR
label1.getStyleClass().add("label1");
TextField txtbox1 = new TextField();
vbox1.getChildren().addAll(label1,txtbox1);
//
VBox vbox2 = new VBox(10);
Label label2 = new Label("Label2");
label2.getStyleClass().add("label2");
TextField txtbox2 = new TextField();
txtbox2.getStyleClass().add("txtbox2");
vbox2.getChildren().addAll(label2,txtbox2);
//HBox.setHgrow(vbox2, Priority.ALWAYS);
// stack panehbox
StackPane.setMargin(hbox, new Insets(20));
//
hbox.getChildren().addAll(vbox1, vbox2);
Scene scene = new Scene (hbox, 300, 250);
primaryStage.setScene(scene);
// scene.getStylesheets().add
//("http://manas9/BareBone_JavaCore/JavaFxCSS1.css");
//OR
scene.getStylesheets().add(javafxtemplate1.
JavaFXTemplate1.class.getResource
("JavaFxCSS1.css").toExternalForm());
primaryStage.show();
}
public static void main(String[] args) throws SQLException {
launch(args);
}
}
|