2016-02-20 90 views
0

晚安,我正在使用JavaFX與一些合作伙伴的應用程序;這個想法是它將被用於Windows和Linux。我們一直在做一些測試,並發現應用程序在兩個操作系統中都顯示不同。JavaFX的DPI awarness

我們正在使用場景Builder.I'm想,如果有人happend碰到類似的問題,以及如何解決它(我已經閱讀過其他類似的帖子,但沒有他們的幫助我)。

這是如何顯示在Windows上: enter image description here

,這是它如何顯示在Linux上: enter image description here

這只是一個例子,因爲它與一切形式的發生。如果有人可以幫助我們,我們將非常感激!

我做下一個函數調用的形式:

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); 
    } 
} 

這裏所要求的形式FXML:

<?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> 
+0

它只是看起來像不同的字體改變按鈕的大小。你能發佈代碼嗎? –

+0

我張貼,我用它來調用所有的形式,任何你需要我很高興發佈它的代碼,是不是這麼大的空間,因爲它的形式是不同的控件之間的間距。 –

+0

以使用[ScenicView(http://fxexperience.com/scenic-view/)兩個操作系統上找出實際的區別是什麼一看應用。相關代碼位於FXML和CSS文件中,然後添加到該文章中。 – hotzst

回答

0

謝謝大家非常多的評論,問題是字體系列和Linux的不承認他們的大小,我所做的就是下載一個字體文件,並把它添加到proyect,創建一個* .css文件:

scene.getStylesheets().add(getClass().getResource("/stock/css.css").toExternalForm()); 
:隨着對外開放之前

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

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

然後將其添加到現場

即使問題得到解決,它看起來很大,仍然有微小的細節時,即時通訊設計我必須拿出空格右側和底部,因爲Windows添加更多的它,似乎並沒有被髮生在Linux上,所以顯示有所不同。

1

Windows默認的字體是從Linux默認的字體,你是不同的正在運行。要檢查此,請在你的TableCell設置預先定義的對象,看看

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