Q&A
Scene BuilderでCSSファイル読み込んで、ボタンが平面的になるボタンを作成し、
画像をファイルから読み込んで挿入し、Scene Builderでプレビューすると↓のようにきちんと表示されますが、
NetBeansで実行すると↓のように反映されません。
Scene Builderではきちんと表示されるのにNetBeansでは反映されないのはなぜでしょうか?
ソースコードを載せておきます。
Java
1package test; 2 3import javafx.application.Application; 4import javafx.fxml.FXMLLoader; 5import javafx.geometry.Rectangle2D; 6import javafx.scene.Parent; 7import javafx.scene.Scene; 8import javafx.stage.Screen; 9import javafx.stage.Stage; 10 11 12public class Test extends Application { 13 14 @Override 15 public void start(Stage stage) throws Exception { 16 17 Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml")); 18 19 20 21 Scene scene = new Scene(root); 22 23 stage.setScene(scene); 24 //画面サイズを取得する(解像度を取得) 25 Rectangle2D gazousyutoku = Screen.getPrimary().getVisualBounds(); 26 27 //最大化してくれるウィンドウ 28 stage.setX(gazousyutoku.getMinX()); 29 //プロパティxの値を設定します。 30 stage.setY(gazousyutoku.getMinY()); 31 //プロパティyの値を設定します。 32 stage.setWidth(gazousyutoku.getWidth()); 33 //プロパティwidthの値を設定します。 34 stage.setHeight(gazousyutoku.getHeight()); 35 //プロパティHeightの値を設定します。 36 stage.setMaximized(true); 37 //Stageを最大化するかどうかを定義 38 stage.show(); 39 } 40 41 /** 42 * @param args the command line arguments 43 */ 44 public static void main(String[] args) { 45 launch(args); 46 } 47 48} 49
FXML↓
FXML
1<?xml version="1.0" encoding="UTF-8"?> 2 3<?import javafx.scene.control.Button?> 4<?import javafx.scene.control.Menu?> 5<?import javafx.scene.control.MenuBar?> 6<?import javafx.scene.control.MenuItem?> 7<?import javafx.scene.control.ToolBar?> 8<?import javafx.scene.image.Image?> 9<?import javafx.scene.image.ImageView?> 10<?import javafx.scene.layout.AnchorPane?> 11<?import javafx.scene.layout.BorderPane?> 12<?import javafx.scene.layout.ColumnConstraints?> 13<?import javafx.scene.layout.GridPane?> 14<?import javafx.scene.layout.RowConstraints?> 15 16<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1"> 17 <children> 18 <BorderPane layoutX="200.0" layoutY="53.0" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="719.0" prefWidth="750.0" AnchorPane.bottomAnchor="-96.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> 19 <top> 20 <GridPane BorderPane.alignment="CENTER"> 21 <columnConstraints> 22 <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> 23 </columnConstraints> 24 <rowConstraints> 25 <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> 26 <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> 27 </rowConstraints> 28 <children> 29 <MenuBar> 30 <menus> 31 <Menu mnemonicParsing="false" text="File"> 32 <items> 33 <MenuItem mnemonicParsing="false" text="Close" /> 34 </items> 35 </Menu> 36 <Menu mnemonicParsing="false" text="Edit"> 37 <items> 38 <MenuItem mnemonicParsing="false" text="Delete" /> 39 </items> 40 </Menu> 41 <Menu mnemonicParsing="false" text="Help"> 42 <items> 43 <MenuItem mnemonicParsing="false" text="About" /> 44 </items> 45 </Menu> 46 </menus> 47 </MenuBar> 48 <ToolBar prefHeight="40.0" prefWidth="200.0" GridPane.rowIndex="1"> 49 <items> 50 <Button mnemonicParsing="false" prefHeight="25.0" prefWidth="30.0" stylesheets="@../../../../test.css"> 51 <graphic> 52 <ImageView fitHeight="19.0" fitWidth="21.0" pickOnBounds="true" preserveRatio="true"> 53 <image> 54 <Image url="@../../../../Visual%20Studio%202013%20Image%20Library/Office%20and%20VS/NewDocument_32x32.png" /> 55 </image> 56 </ImageView> 57 </graphic></Button> 58 </items> 59 </ToolBar> 60 </children> 61 </GridPane> 62 </top> 63 </BorderPane> 64 </children> 65</AnchorPane> 66
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。