我一直在尝试使用从数据库查询的数据加载TableView,但似乎无法使其工作.
这是我尝试用数据库查询项填充数据库的第一次尝试,以防我的代码看起来很糟糕而且远非好.
FXML是通过JavaFx SceneBuilder完成的.
这是数据库查询类:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableView;
public class StudentInfo {
static String JDBC_DRIVER = "org.h2.Driver";
static String DB_URL = "jdbc:h2:file:C:/WAKILI/WAKILIdb";
// Database credentials
static final String USER = "sa";
static final String PASS = "";
public static Connection conn = null;
@FXML
private TableView<StudentInfo> lovelyStudents;
private ObservableList data;
// Public static ObservableList<COA> getAllCOA(){
public void getAllstudentInfo() {
Statement st = null;
ResultSet rs; …Run Code Online (Sandbox Code Playgroud) 我希望将舞台设置为“UNDECORATED”,使其可拖动和最小化。问题是我找不到这样做的方法,因为我遇到的例子是通过插入到 main 方法中的方法来做到这一点的。
我想通过在控制器类中声明的方法来完成这项工作,就像我如何设法使用下面的“WindowClose()”方法一样。
这是我使用 JavaFX 的第二天,如果这似乎是一个太多的常识问题。谢谢大家。
// Main Class/ Method
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Fxmltableview extends Application {
public static String pageSource = "fxml_tableview.fxml";
public static Scene scene;
@Override
public void start(Stage stage) throws Exception {
stage.initStyle(StageStyle.UNDECORATED);
stage.initStyle(StageStyle.TRANSPARENT);
Parent root = FXMLLoader.load(getClass().getResource(pageSource));
scene = new Scene(root, Color.TRANSPARENT);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
..
// The Controller
import javafx.application.Platform;
import javafx.collections.ObservableList; …Run Code Online (Sandbox Code Playgroud) 如何在隐藏的项目上添加花哨的JavaFX事件?
例如,当我显示由按钮点击触发的隐藏标签时,我想使用"淡入淡出"效果.
如何在调用以下方法时添加效果?
@FXML
private void handleButtonAction(ActionEvent event) {
label.setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)