Last active
August 29, 2015 13:57
-
-
Save aoetk/9812635 to your computer and use it in GitHub Desktop.
JavaFXでのスケーリングのテスト用アプリ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import javafx.application.Application; | |
import javafx.fxml.FXMLLoader; | |
import javafx.scene.Parent; | |
import javafx.scene.Scene; | |
import javafx.stage.Stage; | |
public class DpiTestApp extends Application { | |
@Override | |
public void start(Stage primaryStage) throws Exception{ | |
FXMLLoader loader = new FXMLLoader(getClass().getResource("DpiTestView.fxml")); | |
Parent root = loader.load(); | |
primaryStage.setTitle("Dpi Test App"); | |
primaryStage.setScene(new Scene(root)); | |
primaryStage.show(); | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import java.lang.*?> | |
<?import javafx.geometry.*?> | |
<?import javafx.scene.control.*?> | |
<?import javafx.scene.layout.*?> | |
<?import javafx.scene.text.*?> | |
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="240.0" | |
prefWidth="420.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" | |
fx:controller="sample.DpiTestViewController"> | |
<top> | |
<Label text="High DPI Test App" BorderPane.alignment="CENTER_LEFT"> | |
<font> | |
<Font size="36.0"/> | |
</font> | |
</Label> | |
</top> | |
<padding> | |
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/> | |
</padding> | |
<bottom> | |
<HBox alignment="CENTER_LEFT" prefHeight="100.0" spacing="10.0" BorderPane.alignment="CENTER"> | |
<children> | |
<Button mnemonicParsing="false" text="Button001" fx:id="sampleButton" onAction="#loadScaleInformation"/> | |
<Label text="Button size:"/> | |
<Label fx:id="buttonWidth"/> | |
<Label text="x"/> | |
<Label fx:id="buttonHeight"/> | |
</children> | |
</HBox> | |
</bottom> | |
<center> | |
<GridPane vgap="10.0" BorderPane.alignment="CENTER"> | |
<columnConstraints> | |
<ColumnConstraints hgrow="NEVER" minWidth="10.0" prefWidth="100.0"/> | |
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/> | |
</columnConstraints> | |
<rowConstraints> | |
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="BOTTOM" vgrow="SOMETIMES"/> | |
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="TOP" vgrow="SOMETIMES"/> | |
</rowConstraints> | |
<children> | |
<Label text="Current DPI:"/> | |
<Label text="Scene size:" GridPane.rowIndex="1"/> | |
<Label text="" GridPane.columnIndex="1" fx:id="currentDpi"/> | |
<HBox spacing="10.0" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="TOP"> | |
<children> | |
<Label fx:id="sceneWidth"/> | |
<Label text="x"/> | |
<Label fx:id="sceneHeight"/> | |
</children> | |
</HBox> | |
</children> | |
</GridPane> | |
</center> | |
</BorderPane> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import javafx.event.ActionEvent; | |
import javafx.fxml.Initializable; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.Label; | |
import javafx.stage.Screen; | |
import java.net.URL; | |
import java.util.ResourceBundle; | |
public class DpiTestViewController implements Initializable { | |
public Label buttonWidth; | |
public Label buttonHeight; | |
public Label sceneWidth; | |
public Label sceneHeight; | |
public Button sampleButton; | |
public Label currentDpi; | |
@Override | |
public void initialize(URL url, ResourceBundle resourceBundle) { | |
} | |
public void loadScaleInformation(ActionEvent actionEvent) { | |
Scene scene = sceneWidth.getScene(); | |
sceneWidth.setText(Double.toString(scene.getWidth())); | |
sceneHeight.setText(Double.toString(scene.getHeight())); | |
buttonWidth.setText(Double.toString(sampleButton.getWidth())); | |
buttonHeight.setText(Double.toString(sampleButton.getHeight())); | |
Screen screen = Screen.getPrimary(); | |
currentDpi.setText(String.valueOf(screen.getDpi())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment