JavaFX自定义控件主方法

huangapple 未分类评论44阅读模式
英文:

JavaFX Custom Control main method

问题

我正在按照此教程学习使用 JavaFX 创建自定义控件。我注意到他们有一个主方法,但在视频中从未展示过它。

我无法将我的 JAR 导出为可运行的 JAR,因为我需要一个主类,所以我尝试创建一个(下面是代码)。然而,当我尝试将其导入到 SceneBuilder 中时,它没有显示。

主类:

package controls;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {
	
	@Override
	public void start(Stage s) throws Exception {
		Parent root = FXMLLoader.load(getClass().getResource("MessageTab.fxml"));
		s.setScene(new Scene(root));
		s.show();
		
	}

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

当我在 Eclipse 中运行 JAR 时,它显示了 FXML 文件。
我希望将此 JAR 用作自定义控件,而不是应用程序,但我找不到有关如何正确导出它的任何信息。如果您知道我需要做什么,请告诉我。

谢谢!

英文:

I'm following this tutorial regarding custom control creation using JavaFX. I noticed that they had a main method, but they never showed it in the video.

I couldn't export my jar as a runnable jar because I needed a main class, so I tried to create one (code below). However, when I tried to import it into SceneBuilder, it didn't show.

Main class:

package controls;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {
	
	@Override
	public void start(Stage s) throws Exception {
		Parent root = FXMLLoader.load(getClass().getResource("MessageTab.fxml"));
		s.setScene(new Scene(root));
		s.show();
		
	}

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

When I ran the jar in eclipse, it displayed the fxml file.
I want to use this jar as a custom control, not an application, but I couldn't find anything about what I needed to do to export it properly. If you know what I need to do, please let me know.

Thanks!

huangapple
  • 本文由 发表于 2020年7月24日 23:34:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/63076799.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定