Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javafx将新的fxml文件加载到滚动窗格中_Java_Javafx - Fatal编程技术网

Javafx将新的fxml文件加载到滚动窗格中

Javafx将新的fxml文件加载到滚动窗格中,java,javafx,Java,Javafx,是否可以将新的fxml文件加载到滚动窗格中 有关更多详细信息,请查看此图像 请帮助我。以下代码显示如何使用FXMLLoader将字符串转换为某些FXML对象。 然后,通常的GetChildren.AddXX可以用于分配到任何需要的位置 罗伯特 package ic.ac.uk.relationshipvisualiser.app; import java.io.ByteArrayInputStream; import java.io.InputStream; import javafx.ap

是否可以将新的fxml文件加载到滚动窗格中

有关更多详细信息,请查看此图像


请帮助我。

以下代码显示如何使用FXMLLoader将字符串转换为某些FXML对象。 然后,通常的GetChildren.AddXX可以用于分配到任何需要的位置

罗伯特

package ic.ac.uk.relationshipvisualiser.app;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

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

public class tmpTest extends Application {

    public static void main(String[] args) {
        System.out.println("Start tmpTest");
        launch(args);
        System.out.println("Start tmpTest");
    }

    final Group m_root = new Group();

    @Override
    public void start(Stage primaryStage) throws Exception {
        String sample_fxml = 
                "<?import javafx.scene.control.Label?>" +
                "<?import javafx.scene.Group?>" +
                "<Group xmlns:fx=\"http://javafx.com/fxml\">" +
                "       <Label fx:id=\"Name\" style=\"-fx-font-weight: bold;\" alignment=\"CENTER\">It worked</Label>" +        
                "</Group>";

        InputStream stream = new ByteArrayInputStream(sample_fxml.getBytes("UTF-8"));
        FXMLLoader l = new FXMLLoader();

        Group mG = (Group) l.load(stream);

        m_root.getChildren().add(mG);

        primaryStage.setScene(new Scene(m_root));

        primaryStage.show();

    }

}

关于我上一个显示从文件读取的答案: 首先创建一个文件c:\test.fxml,其中包含:

<?import javafx.scene.control.Label?>
<?import javafx.scene.Group?>
<Group xmlns:fx="http://javafx.com/fxml">
<Label fx:id="Name" style="-fx-font-weight: bold;" alignment="CENTER">It worked</Label>     
</Group>

观看此图像我想在scrollpane[link]中添加fxml,而不是在运行时启动时,或者在startupI尝试演示如何将字符串加载到一组fxml对象后执行的任何函数中。在这个例子中,我是在启动时做的,但在任何情况下都可以放置完全相同的代码。您还需要将其更改为从实际的FXML文件中读取字符串。您能否为我提供显示如何从FXML文件中读取字符串的链接?请同时为我提供以下提示:
package ic.ac.uk.relationshipvisualiser.app;

import java.io.FileInputStream;
import java.io.InputStream;

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

public class tmpTest extends Application {

    public static void main(String[] args) {
        System.out.println("Start tmpTest");
        launch(args);
        System.out.println("Start tmpTest");
    }
    final Group m_root = new Group();

    @Override
    public void start(Stage primaryStage) throws Exception {
        InputStream stream = new FileInputStream("c:\\test.fxml");
        FXMLLoader l = new FXMLLoader();
        Group mG = (Group) l.load(stream);

        m_root.getChildren().add(mG);
        primaryStage.setScene(new Scene(m_root));
        primaryStage.show();
    }
}