質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
JavaFX

JavaFXとは、Java仮想マシン上で動作するリッチインターネットアプリケーション (RIA) のGUIライブラリです。Swingとは異なり、FXMLと呼ばれる XMLとCSSを併用してデザインを記述します。

Q&A

解決済

1回答

1086閲覧

新しいウィンドウを表示しようとすると、代わりにコンソールにFXMLのファイルの場所が記述される。

ryu-bamboo

総合スコア9

JavaFX

JavaFXとは、Java仮想マシン上で動作するリッチインターネットアプリケーション (RIA) のGUIライブラリです。Swingとは異なり、FXMLと呼ばれる XMLとCSSを併用してデザインを記述します。

1グッド

0クリップ

投稿2021/04/30 13:25

編集2021/05/01 05:07

JavaFXでスケジュール表を作っています。機能は、よくスケジュール帳で見かけるようなフォーマット、予定表の部分を押すとマウスでクリックすると予定を設定できるようなものです。

状況を説明すると、マウスのイベントの設定まで終わって、実行し、イベントを起こしてみると、ファイルの場所が記述されたという感じです、原因を教えていただけると嬉しいです。

Controller

1/** 2 * Sample Skeleton for 'ScheduleIndividual.fxml' Controller Class 3 */ 4 5package application; 6 7import java.io.IOException; 8import java.net.URL; 9import java.time.LocalTime; 10import java.util.ResourceBundle; 11 12import javafx.fxml.FXML; 13import javafx.fxml.FXMLLoader; 14import javafx.scene.Scene; 15import javafx.scene.control.Label; 16import javafx.scene.input.MouseEvent; 17import javafx.scene.layout.AnchorPane; 18import javafx.scene.layout.VBox; 19import javafx.stage.Stage; 20 21public class SceduleTableController { 22 23 24 @FXML // ResourceBundle that was given to the FXMLLoader 25 private ResourceBundle resources; 26 27 @FXML // URL location of the FXML file that was given to the FXMLLoader 28 private URL location; 29 30 @FXML // fx:id="pane" 31 private VBox pane; // Value injected by FXMLLoader 32 33 @FXML // fx:id="aPane" 34 private AnchorPane aPane; // Value injected by FXMLLoader 35 36 @FXML // fx:id="aPane" 37 private VBox scheduleIndividual; // Value injected by FXMLLoader 38 39 @FXML 40 void sets(MouseEvent event) { 41 try { 42 showSecondWindow(); 43 } catch (Exception ex) { 44 System.out.println(ex.getMessage()); 45 } 46 } 47 48 void showSecondWindow() throws IOException { 49 50 FXMLLoader loader = new FXMLLoader(getClass().getResource("ScheduleSelect.fxml")); 51 AnchorPane root = (AnchorPane) loader.load(); 52 Scene scene = new Scene(root); 53 Stage stage = new Stage(); 54 stage.setScene(scene); 55 stage.showAndWait(); 56 57 } 58 59 60 @SuppressWarnings("static-access") 61 @FXML // This method is called by the FXMLLoader when initialization is complete 62 void initialize() { 63 var sLabel = new Label(); 64 var data = new ScheduleData("部活",LocalTime.of(12,0),LocalTime.of(13,0),"試合"); 65 double stNum = (data.getsTime().getHour()+data.getsTime().getMinute()/60)*30+4; 66 double ftNum = (data.getfTime().getHour()+data.getfTime().getMinute()/60)*30+4; 67 double tNum = ftNum-stNum; 68 String str = data.gettitle()+"\n"+data.gettime()+"\n"+data.getDetail(); 69 sLabel.setText(str); 70 aPane.getChildren().add(sLabel); 71 aPane. setTopAnchor(sLabel, stNum); 72 sLabel.setPrefHeight(tNum); 73 74 75 76 77 assert pane != null : "fx:id=\"pane\" was not injected: check your FXML file 'ScheduleIndividual.fxml'."; 78 79 } 80} 81

ScheduleTable

1<?xml version="1.0" encoding="UTF-8"?> 2 3<?import javafx.scene.text.*?> 4<?import javafx.scene.control.*?> 5<?import javafx.geometry.*?> 6<?import java.lang.*?> 7<?import javafx.scene.layout.*?> 8<?import javafx.scene.layout.BorderPane?> 9<?import javafx.scene.layout.AnchorPane?> 10 11<VBox fx:id="scheduleIndividual" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="130.0" styleClass="ScheduleTable" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SceduleTableController"> 12 <children> 13 <AnchorPane prefHeight="100.0" prefWidth="130.0"> 14 <children> 15 <Label text="日付" textAlignment="CENTER" AnchorPane.bottomAnchor="60.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="60.0" AnchorPane.topAnchor="0.0"> 16 <font> 17 <Font name="Monospaced Regular" size="18.0" /> 18 </font> 19 </Label> 20 <CheckBox mnemonicParsing="false" text="CheckBox" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0" /> 21 <CheckBox mnemonicParsing="false" text="CheckBox" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="57.0" /> 22 <CheckBox mnemonicParsing="false" text="CheckBox" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="74.0" /> 23 </children> 24 </AnchorPane> 25 <ScrollPane prefHeight="400.0" prefWidth="130.0" vbarPolicy="ALWAYS"> 26 <content> 27 <HBox minWidth="130.0" prefHeight="740.0" prefWidth="130.0"> 28 <children> 29 <AnchorPane prefHeight="740.0" prefWidth="30.0"> 30 <children> 31 <Label text="0:00" AnchorPane.topAnchor="0.0" /> 32 <Label text="1:00" AnchorPane.topAnchor="30.0" /> 33 <Label text="2:00" AnchorPane.topAnchor="60.0" /> 34 <Label text="3:00" AnchorPane.topAnchor="90.0" /> 35 <Label text="4:00" AnchorPane.topAnchor="120.0" /> 36 <Label text="5:00" AnchorPane.topAnchor="150.0" /> 37 <Label text="6:00" AnchorPane.topAnchor="180.0" /> 38 <Label text="7:00" AnchorPane.topAnchor="210.0" /> 39 <Label text="8:00" AnchorPane.topAnchor="240.0" /> 40 <Label text="9:00" AnchorPane.topAnchor="270.0" /> 41 <Label text="10:00" AnchorPane.topAnchor="300.0" /> 42 <Label text="11:00" AnchorPane.topAnchor="330.0" /> 43 <Label text="12:00" AnchorPane.topAnchor="360.0" /> 44 <Label text="13:00" AnchorPane.topAnchor="390.0" /> 45 <Label text="14:00" AnchorPane.topAnchor="420.0" /> 46 <Label text="15:00" AnchorPane.topAnchor="450.0" /> 47 <Label text="16:00" AnchorPane.topAnchor="480.0" /> 48 <Label text="17:00" AnchorPane.topAnchor="510.0" /> 49 <Label text="18:00" AnchorPane.topAnchor="540.0" /> 50 <Label text="19:00" AnchorPane.topAnchor="570.0" /> 51 <Label text="20:00" AnchorPane.topAnchor="600.0" /> 52 <Label text="21:00" AnchorPane.topAnchor="630.0" /> 53 <Label text="22:00" AnchorPane.topAnchor="660.0" /> 54 <Label text="23:00" AnchorPane.topAnchor="690.0" /> 55 <Label text="24:00" AnchorPane.topAnchor="720.0" /> 56 </children> 57 </AnchorPane> 58 <AnchorPane fx:id="aPane" onMouseClicked="#sets" prefHeight="740.0" prefWidth="100.0" /> 59 </children> 60 </HBox> 61 </content> 62 </ScrollPane> 63 <TextArea prefHeight="100.0" prefWidth="130.0" text="感想" /> 64 </children> 65</VBox>

ScheduleSelect

1<?xml version="1.0" encoding="UTF-8"?> 2 3<?import javafx.scene.text.*?> 4<?import javafx.scene.control.*?> 5<?import java.lang.*?> 6<?import javafx.scene.layout.*?> 7<?import javafx.scene.layout.AnchorPane?> 8 9 10<AnchorPane prefHeight="400.0" prefWidth="300.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" 11 fx:controller="application.ScheduleTableController"> 12 <children> 13 <Label layoutX="77.0" layoutY="14.0" prefHeight="27.0" prefWidth="127.0" text="予定を追加する" textAlignment="CENTER" AnchorPane.leftAnchor="77.0" AnchorPane.rightAnchor="96.0" AnchorPane.topAnchor="14.0"> 14 <font> 15 <Font size="18.0" /> 16 </font> 17 </Label> 18 <Label layoutX="5.0" layoutY="53.0" prefHeight="20.0" prefWidth="46.0" text="パッケージ" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="53.0" /> 19 <Label layoutX="14.0" layoutY="93.0" text="名前" /> 20 <Label layoutX="14.0" layoutY="133.0" prefHeight="17.0" prefWidth="28.0" text="日付" /> 21 <Label layoutX="14.0" layoutY="172.0" text="時間" /> 22 <Label layoutX="17.0" layoutY="259.0" text="メモ" /> 23 <ComboBox fx:id="packageSelect" layoutX="66.0" layoutY="51.0" prefHeight="25.0" prefWidth="121.0" promptText="新規作成の場合は入力" /> 24 <TextField fx:id="scheduleName" layoutX="64.0" layoutY="89.0" prefHeight="25.0" prefWidth="127.0" /> 25 <ComboBox fx:id="year" layoutX="53.0" layoutY="129.0" prefHeight="25.0" prefWidth="50.0" /> 26 <Label layoutX="107.0" layoutY="133.0" prefHeight="17.0" prefWidth="14.0" text="年" /> 27 <Label layoutX="224.0" layoutY="93.0" text="*必須" /> 28 <Label layoutX="248.0" layoutY="160.0" text="*必須" /> 29 <ComboBox fx:id="sMinute" layoutX="120.0" layoutY="168.0" prefHeight="25.0" prefWidth="36.0" /> 30 <ComboBox fx:id="sHour" layoutX="64.0" layoutY="169.0" prefHeight="25.0" prefWidth="50.0" /> 31 <Label layoutX="114.0" layoutY="161.0" prefHeight="20.0" prefWidth="6.0" text=":"> 32 <font> 33 <Font size="28.0" /> 34 </font> 35 </Label> 36 <Label layoutX="100.0" layoutY="198.0" prefHeight="20.0" prefWidth="20.0" text="~"> 37 <font> 38 <Font size="16.0" /> 39 </font> 40 </Label> 41 <Label layoutX="175.0" layoutY="190.0" prefHeight="20.0" prefWidth="6.0" text=":"> 42 <font> 43 <Font size="28.0" /> 44 </font> 45 </Label> 46 <ComboBox fx:id="fHour" layoutX="125.0" layoutY="198.0" prefHeight="25.0" prefWidth="50.0" /> 47 <ComboBox fx:id="fMinute" layoutX="181.0" layoutY="197.0" prefHeight="25.0" prefWidth="36.0" /> 48 <TextArea fx:id="memo" layoutX="53.0" layoutY="259.0" onMouseClicked="#clickMemo" prefHeight="91.0" prefWidth="226.0" /> 49 <Button fx:id="sakusei" layoutX="113.0" layoutY="359.0" mnemonicParsing="false" onAction="#jikkou" prefHeight="27.0" prefWidth="64.0" text="作成" /> 50 <Label layoutX="180.0" layoutY="133.0" prefHeight="17.0" prefWidth="14.0" text="月" /> 51 <ComboBox fx:id="month" layoutX="125.0" layoutY="129.0" prefHeight="25.0" prefWidth="50.0" /> 52 <ComboBox fx:id="day" layoutX="197.0" layoutY="129.0" prefHeight="25.0" prefWidth="50.0" /> 53 <Label layoutX="252.0" layoutY="133.0" prefHeight="17.0" prefWidth="14.0" text="日" /> 54 </children> 55</AnchorPane>

実行結果

boochnich👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

Exceptionが投げられていただけでした。

投稿2021/05/01 08:00

ryu-bamboo

総合スコア9

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問