我有一个简单的 JavaFX 应用程序,一个带有 AnchorPane 的 BorderLayout,在两个窗格中,一个包含一个 HBox 和一个带有 TextArea 和 ListView 的 VBox。当我增加窗口尺寸时,我希望它们的宽度也增加。我已经在控件上尝试了 Vgrow/Hgrow = 'ALWAYS' 和最大宽度/最大高度 = 'MAX_VALUE',但没有任何效果。-(我使用场景生成器创建 fxml)
FXML 如下:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<BorderPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1">
<center>
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" BorderPane.alignment="CENTER">
<children>
<Pane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
<Pane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="200.0">
<children>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0">
<children>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" HBox.hgrow="ALWAYS">
<children>
<TextArea …Run Code Online (Sandbox Code Playgroud) 我创建了一个项目,需要一个 tomcat 服务器来托管一个小网站。现在我想向该项目添加一个 JavaFX 应用程序。这也应该在 Tomcat 启动时启动,但不幸的是没有任何反应。FX 已添加到项目库中。
public class Start {
public static void main( String args[] )
{
try {
Tomcat tomcat = new Tomcat( );
String webappDirectory = new File( "src/main/webapp" ).getAbsolutePath( );
tomcat.setPort( 8080 );
Context context = tomcat.addWebapp( "", webappDirectory );
Tomcat.addServlet( context, "blockchain", new ServletContainer( new Applications( ) ) );
context.addServletMappingDecoded( "/blockchain/api/*", "blockchain" );
tomcat.start( );
tomcat.getServer( ).await( );
ConfigurationGui config = new ConfigurationGui();
Stage stage = new Stage();
config.start(stage);
}
catch ( Exception …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的大学项目制作一部交互式视觉小说,但我不知道如何仅用一个按钮将标签的文本更新为下一行对话。
\npublic void NicoleDialogue() {\n String[] NDialogue = {"My name is Tala Nicole Dimaapi Valdez / Joshua Manuel Garcia Reyes, I know a long ass name but I\xe2\x80\x99m filipino what can I say?",\n "I\xe2\x80\x99m a student of DLSU, one of the most prestigious universities in the country and today I will join GreenGiant FM, an organization for people who want to become radio hosts or who are just interested in radio hosting in general.",\n "It is my first time …Run Code Online (Sandbox Code Playgroud) 您Swing可以使用java.awt.Toolkit和java.awt.datatransfer.Clipboard类来复制系统剪贴板中的文本值,我正在寻找一种解决方案来使用?将String变量的值复制到系统剪贴板。JavaFX
我想知道为什么我的 Mandelbrot 集的背景不如另一张图片的背景好。另外,如果我将 iterationChecker 的 if 语句中的数字 4 设置为大于 4 的任何其他数字,为什么 Mandelbrot 集仍然显示?
曼德尔布罗特集,背景看起来是歪的:
我希望背景看起来像这样:
我是 Maven 新手。我需要包括
private javafx.embed.swing.JFXPanel jFXPanel1;
Run Code Online (Sandbox Code Playgroud)
使用 Maven + Jigsaw 模块的新项目。
我的包有以下问题javafx.embed.swing。
我以为添加这个依赖项会起作用,但事实并非如此。
private javafx.embed.swing.JFXPanel jFXPanel1;
Run Code Online (Sandbox Code Playgroud)
在全新安装时,我看到以下内容
(包 javafx.embed.swing 在未命名模块中声明,但模块 com.my.module 不读取它)
我不明白这一点。我看到那个JAR,它只有一个清单文件,没有任何.class文件,这让我更加困惑。
如果我查看 m2 文件夹,我会看到一个不同的 JAR,具有相同的前缀,但带有win后缀,并且在那里我看到了该包。
我认为这就是分类器
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-swing -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>19</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我想,但我不知道,这个 jar 是否被 Maven 选择,但似乎没有,因为我在 IntelliK 库中没有看到它。
我对 JavaFX 没有任何问题,一切都是模块化的并且正在运行。我只有这个罐子有问题。
- - - - - - - - - - - - - - -更新 - - - - - - - - - - ----------------
这里的罪魁祸首是 IntellijIdea,我确实单击了 …
对于上下文,我在 Intellij 中有一个Maven 项目结构,还有/target/classes/
我收到错误的代码:
@Override
public void start(Stage stage) throws IOException {
Parent root;
FXMLLoader fxmlLoader = new FXMLLoader();
// Below line has the problem of loading image inside fxml file.
root = fxmlLoader.load(getClass().getClassLoader().getResourceAsStream("AuthorizationPage.fxml"));
// not used in code but below line returns inputstream object which is not null so the image loads fine
when independently verified.
// System.out.println(Objects.isNull(getClass().getClassLoader().getResourceAsStream("sign-up-logo.png")));
//Below Line works fine and loads fxml file correctly with images.
root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/AuthorizationPage.fxml")));
Scene scene = …Run Code Online (Sandbox Code Playgroud) 我已在 settings.json 文件中添加此 java classPath,以在 Ubuntu 22.04 的 vscode 中使用 JavaFx
"java.classPath": "/usr/share/openjfx/lib",
Run Code Online (Sandbox Code Playgroud)
添加此行后,Java 编译器之前向我显示的与 JavaFX 包和方法相关的错误消息消失了。JavaFX 的智能感知和建议也正在发挥作用。
但我在 settings.json 文件中收到此错误消息
无法从“vscode://schemas/settings/folder”加载架构:无法打开 vscode://schemas/settings/folder。详细信息:无法解析资源 vscode://schemas/settings/folder 的文本模型内容。
我的 settings.json 文件如下所示:
{
"java.classPath": "/usr/share/openjfx/lib",
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar",
"/usr/share/openjfx/lib/javafx.web.jar",
"/usr/share/openjfx/lib/javafx.swing.jar",
"/usr/share/openjfx/lib/javafx.media.jar",
"/usr/share/openjfx/lib/javafx.graphics.jar",
"/usr/share/openjfx/lib/javafx.fxml.jar",
"/usr/share/openjfx/lib/javafx.controls.jar",
"/usr/share/openjfx/lib/javafx.base.jar"
],
"java.debug.settings.onBuildFailureProceed": true
}
Run Code Online (Sandbox Code Playgroud)
我尝试通过从 chatGPT 获得的链接更改架构文件夹,并在这里搜索了一些与此相关的问题。但它们都不起作用。
根据我的理解,getCharacter()的方法KeyEvent应该返回一个char类型。
例如,如果我必须检查键入的键是否是数字,我可以使用Character.isDigit(e.getCharacter())not Character.isDigit(e.getCharacter().charAt(0))。
e.getCharacter().length()我还通过打印it always returns来检查返回字符串的长度1。该字符串有任何解释或其他用法吗?
如何为 javaFX 项目的单独 css 文件中的所有线条对象应用某种样式?这是java代码:
package com.example.demo;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
Pane root = new Pane();
Scene scene = new Scene(root, 1200, 800);
stage.setTitle("Simulink viewer");
Label l1 = new Label("hdkhsd");
l1.setLayoutX(100);
l1.setLayoutY(100);
Label l2 = new Label("helle");
l2.setLayoutX(400);
l2.setLayoutY(400);
root.getChildren().addAll(l1,l2);
Line l = new Line(10,10,90,90);
root.getChildren().add(l);
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
stage.setScene(scene);
stage.show();
}
public static void main(String[] …Run Code Online (Sandbox Code Playgroud)