FXML and high dpi screens
John Smith
send2jsmith at gmail.com
Fri May 17 03:56:28 PDT 2013
How about using an expression binding.
For 35em x 25em you could write:
prefWidth="${35*u.em}" prefHeight="${25*u.em}"
It's not 100% concise, but perhaps passable.
These kind of sizing expressions work in scene builder 1.1, which is nice.
-------
Here is an example using a Rectangle to store the width and height modifiers for the fxml file.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<StackPane xmlns:fx="http://javafx.com/fxml">
<fx:define>
<Rectangle fx:id="s" width="13" height="13"/>
</fx:define>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="${22 * s.width}" prefWidth="${14 * s.height}">
<children>
<Button layoutX="${4 * s.width}" layoutY="${ 5 * s.height}" prefWidth="${6 * s.width}" text="Top" />
<Button layoutX="${4 * s.width}" layoutY="${10 * s.height}" prefWidth="${6 * s.width}" text="Middle" />
<Button layoutX="${4 * s.width}" layoutY="${15 * s.height}" prefWidth="${6 * s.width}" text="Bottom" />
</children>
</AnchorPane>
</StackPane>
-------
Or instead, you can create your own unit class and use it in your sizing expressions, for example:
package org.jewelsea.measure;
public class Measurement {
private double em;
public void setEm(double em) { this.em = em; }
public double getEm() { return em; }
}
. . .
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import org.jewelsea.measure.Measurement?>
<?scenebuilder-classpath-element .?>
<StackPane xmlns:fx="http://javafx.com/fxml">
<fx:define>
<Measurement fx:id="u" em="26.0" />
</fx:define>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="${22*u.em}" prefWidth="${14*u.em}">
<children>
<Button layoutX="${4*u.em}" layoutY="${ 5*u.em}" prefWidth="${6*u.em}" text="Top" />
<Button layoutX="${4*u.em}" layoutY="${10*u.em}" prefWidth="${6*u.em}" text="Middle" />
<Button layoutX="${4*u.em}" layoutY="${15*u.em}" prefWidth="${6*u.em}" text="Bottom" />
</children>
</AnchorPane>
</StackPane>
On May 16, 2013, at 11:51 AM, Danno Ferrin <danno.ferrin at shemnon.com> wrote:
> Executive summary: Is there any way in FXML to specify the sizes of the
> components in units other than pixels? Either now or in the future?
>
> So I am running a Java Swing Application on a Surface tablet with multiple
> embedded FXPanels (mostly to deal with cross toolkit dialog modality... an
> issue for another thread). In order to not get the horrible blurred view
> (since surface does 150% font scaling) I turn off the dpi fixing for the
> java app, so the swing app is pixel to pixel for the most part, with some
> dramatic sizing issues with the XP theming (an issue I don't expect ever to
> be fixed).
>
> So I have an FXML panel that is supposed to be 560x400, and I literally get
> 560px by 400px. But the widgets are all sized in EM, which respects the
> native DPI scale. I don't want to turn that off, because in this case I
> like it. But the widgets scale up, so it sizes like a 373.333x266.666
> panel. What I do want to be able to do is specify the FXML sizes in EM, so
> I would call it 35em x 25em. Is there a way in FXML to specify these? Or
> will I have to do multiple FXMLs mechanically scaling the sizes up. Or is
> there some escape sequence or auxiliary data I can add to say "scale pixel
> sizes by 150%"?
More information about the openjfx-dev
mailing list