Gabriel Tortomano
Gabriel Tortomano

Reputation: 115

JavaFX DPI awarness

Good night, I'm making an application using javaFx with some partners; the idea is that it's going to be used in Windows and Linux. We've been doing some testing and seen that the application displays different in both OS.

We are using Scene Builder.I'm wondering if someone happend to come across a similar problem and how you solve it(I've already read other similar post but none of them helped me).

This is how it displays on Windows: enter image description here

And this is how it displays on Linux: enter image description here

This is just one example as it happens with all forms. If there's someone out there that could help, we would really appreciate it!!

I made the next function to call the forms:

private void OpenForm(String form, String title) {
    try
    {
        FXMLLoader fxmlLoader1 = new FXMLLoader(getClass().getResource(form));
        Parent root;
        root = fxmlLoader1.load();
        Stage stage = new Stage();
        stage.setScene(new Scene(root));
        stage.setTitle(title);
        stage.setResizable(false);
        stage.show();

    }catch (Exception ex)
    {
        Msg(3,"Program error","It appears there's something wrong : ",ex.getMessage().toString());
        System.out.println(ex);
    }
}

Here's the FXML of the form as requested:

    <?xml version="1.0" encoding="UTF-8"?>
    <?import javafx.scene.control.Button?>
    <?import javafx.scene.control.TableColumn?>
    <?import javafx.scene.control.TableView?>
    <?import javafx.scene.layout.AnchorPane?>

    <AnchorPane prefHeight="346.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="GUI.Almacen.ClientesMod">
       <children>
       <TableView fx:id="tvClientes" layoutX="4.0" layoutY="6.0" prefHeight="310.0" prefWidth="638.0">
       <columns>
        <TableColumn fx:id="tcIdCliente" prefWidth="75.0" text="RacF de Cliente" />
      <TableColumn fx:id="tcNombre" prefWidth="75.0" text="Nombre" />
      <TableColumn fx:id="tcDivision" prefWidth="75.0" text="División" />
    </columns>
     <columnResizePolicy>
        <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
     </columnResizePolicy>
  </TableView>
  <Button fx:id="btnModificar" disable="true" layoutX="535.0" layoutY="320.0" mnemonicParsing="false" onAction="#abrirModificarCliente" text="Modificar Cliente" />
  <Button fx:id="btnAgregar" layoutX="432.0" layoutY="320.0" mnemonicParsing="false" onAction="#abrirAgregarCliente" text="Agregar Cliente" />
    </children>
    </AnchorPane>

Upvotes: 0

Views: 1251

Answers (2)

Gabriel Tortomano
Gabriel Tortomano

Reputation: 115

Thank you all very much for commenting, The problem was the font family and size as Linux wasn't recognizing them, what I did was download a font file and add it to the proyect, create a *.css file with:

    @font-face {
         src: url("Roboto-Regular.ttf");
    }

    .root {
        -fx-font-family: "Roboto Regular";
        -fx-font-size: 12px;
     }

And then add it to the scene before opening it with :

scene.getStylesheets().add(getClass().getResource("/stock/css.css").toExternalForm());

Even though the problem is solved and it looks great, there's still the tiny detail that when im designing I have to take out the spaces to the right and bottom because Windows add more of it, that doesn't seem to be happening on Linux so there's a difference in display.

Upvotes: 0

Elltz
Elltz

Reputation: 10859

The windows default Font is different from the Linux default Font you are running on. To check this please set a pre-defined object and see

in your TableCell

{
   setFont(Font.font(Font.getFontNames().get(4), size));
}

Upvotes: 1

Related Questions