Creating buttons in Java with custom font causes buttons to have strange shape










1















I've been trying to create javafx buttons with a custom font. The font is in the resources directory of my project and applied to the buttons via a css stylesheet. The problem is that the buttons become really tall. As soon as I remove the css line that changes the font, the buttons look just as usual. The buttons themselves are inside a HBox which is in the bottom region of a BorderPane. Does anyone have an idea how to fix this? Manually changing the dimension doesn't help.






@font-face 
font-family: 'MODERNA';
src: url('/fonts/MODERNA_.ttf');


.label
-fx-font-family: 'MODERNA';
-fx-font-size: 20;


.button .text
-fx-font-family: 'MODERNA';


.button
-fx-background-color: #F5E050;
-fx-pref-height: 30px;
-fx-pref-width: 100px;





strange, disproportioned buttons with custom font
normal looking buttons with standard font










share|improve this question
























  • Does setting the maxHeight of the Button change it?

    – Zephyr
    Nov 13 '18 at 21:33











  • @Zephyr maxHeight does not change anything, no.

    – Snuffduff
    Nov 14 '18 at 12:17











  • I've now switched over to try and work with scenebuilder but the problem persists

    – Snuffduff
    Nov 14 '18 at 12:18












  • You'll need to provide a Minimal, Complete, and Verifiable example for us to really figure out what's happening.

    – Zephyr
    Nov 14 '18 at 13:24















1















I've been trying to create javafx buttons with a custom font. The font is in the resources directory of my project and applied to the buttons via a css stylesheet. The problem is that the buttons become really tall. As soon as I remove the css line that changes the font, the buttons look just as usual. The buttons themselves are inside a HBox which is in the bottom region of a BorderPane. Does anyone have an idea how to fix this? Manually changing the dimension doesn't help.






@font-face 
font-family: 'MODERNA';
src: url('/fonts/MODERNA_.ttf');


.label
-fx-font-family: 'MODERNA';
-fx-font-size: 20;


.button .text
-fx-font-family: 'MODERNA';


.button
-fx-background-color: #F5E050;
-fx-pref-height: 30px;
-fx-pref-width: 100px;





strange, disproportioned buttons with custom font
normal looking buttons with standard font










share|improve this question
























  • Does setting the maxHeight of the Button change it?

    – Zephyr
    Nov 13 '18 at 21:33











  • @Zephyr maxHeight does not change anything, no.

    – Snuffduff
    Nov 14 '18 at 12:17











  • I've now switched over to try and work with scenebuilder but the problem persists

    – Snuffduff
    Nov 14 '18 at 12:18












  • You'll need to provide a Minimal, Complete, and Verifiable example for us to really figure out what's happening.

    – Zephyr
    Nov 14 '18 at 13:24













1












1








1








I've been trying to create javafx buttons with a custom font. The font is in the resources directory of my project and applied to the buttons via a css stylesheet. The problem is that the buttons become really tall. As soon as I remove the css line that changes the font, the buttons look just as usual. The buttons themselves are inside a HBox which is in the bottom region of a BorderPane. Does anyone have an idea how to fix this? Manually changing the dimension doesn't help.






@font-face 
font-family: 'MODERNA';
src: url('/fonts/MODERNA_.ttf');


.label
-fx-font-family: 'MODERNA';
-fx-font-size: 20;


.button .text
-fx-font-family: 'MODERNA';


.button
-fx-background-color: #F5E050;
-fx-pref-height: 30px;
-fx-pref-width: 100px;





strange, disproportioned buttons with custom font
normal looking buttons with standard font










share|improve this question
















I've been trying to create javafx buttons with a custom font. The font is in the resources directory of my project and applied to the buttons via a css stylesheet. The problem is that the buttons become really tall. As soon as I remove the css line that changes the font, the buttons look just as usual. The buttons themselves are inside a HBox which is in the bottom region of a BorderPane. Does anyone have an idea how to fix this? Manually changing the dimension doesn't help.






@font-face 
font-family: 'MODERNA';
src: url('/fonts/MODERNA_.ttf');


.label
-fx-font-family: 'MODERNA';
-fx-font-size: 20;


.button .text
-fx-font-family: 'MODERNA';


.button
-fx-background-color: #F5E050;
-fx-pref-height: 30px;
-fx-pref-width: 100px;





strange, disproportioned buttons with custom font
normal looking buttons with standard font






@font-face 
font-family: 'MODERNA';
src: url('/fonts/MODERNA_.ttf');


.label
-fx-font-family: 'MODERNA';
-fx-font-size: 20;


.button .text
-fx-font-family: 'MODERNA';


.button
-fx-background-color: #F5E050;
-fx-pref-height: 30px;
-fx-pref-width: 100px;





@font-face 
font-family: 'MODERNA';
src: url('/fonts/MODERNA_.ttf');


.label
-fx-font-family: 'MODERNA';
-fx-font-size: 20;


.button .text
-fx-font-family: 'MODERNA';


.button
-fx-background-color: #F5E050;
-fx-pref-height: 30px;
-fx-pref-width: 100px;






java css button javafx fonts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 19:52









Robert Perez

12210




12210










asked Nov 13 '18 at 19:45









SnuffduffSnuffduff

63




63












  • Does setting the maxHeight of the Button change it?

    – Zephyr
    Nov 13 '18 at 21:33











  • @Zephyr maxHeight does not change anything, no.

    – Snuffduff
    Nov 14 '18 at 12:17











  • I've now switched over to try and work with scenebuilder but the problem persists

    – Snuffduff
    Nov 14 '18 at 12:18












  • You'll need to provide a Minimal, Complete, and Verifiable example for us to really figure out what's happening.

    – Zephyr
    Nov 14 '18 at 13:24

















  • Does setting the maxHeight of the Button change it?

    – Zephyr
    Nov 13 '18 at 21:33











  • @Zephyr maxHeight does not change anything, no.

    – Snuffduff
    Nov 14 '18 at 12:17











  • I've now switched over to try and work with scenebuilder but the problem persists

    – Snuffduff
    Nov 14 '18 at 12:18












  • You'll need to provide a Minimal, Complete, and Verifiable example for us to really figure out what's happening.

    – Zephyr
    Nov 14 '18 at 13:24
















Does setting the maxHeight of the Button change it?

– Zephyr
Nov 13 '18 at 21:33





Does setting the maxHeight of the Button change it?

– Zephyr
Nov 13 '18 at 21:33













@Zephyr maxHeight does not change anything, no.

– Snuffduff
Nov 14 '18 at 12:17





@Zephyr maxHeight does not change anything, no.

– Snuffduff
Nov 14 '18 at 12:17













I've now switched over to try and work with scenebuilder but the problem persists

– Snuffduff
Nov 14 '18 at 12:18






I've now switched over to try and work with scenebuilder but the problem persists

– Snuffduff
Nov 14 '18 at 12:18














You'll need to provide a Minimal, Complete, and Verifiable example for us to really figure out what's happening.

– Zephyr
Nov 14 '18 at 13:24





You'll need to provide a Minimal, Complete, and Verifiable example for us to really figure out what's happening.

– Zephyr
Nov 14 '18 at 13:24












1 Answer
1






active

oldest

votes


















0














I found a solution and wanted to let anyone having the same problem know.
@Zephyr wasn't far off, however it was maxHeight but minHeight that created the problem. It has to be set to USE_PREF_SIZE in the SceneBuilder instead of USE_COMPUTED_SIZE wich seems to be the default value. After that simply change you prefSize in SceneBuilder's UI and everything works out great. The problem must have been the system failing to calculate the correct height on its own, for whatever reason, proably something to do with the font, because it didn't happen with any other fonts.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288425%2fcreating-buttons-in-java-with-custom-font-causes-buttons-to-have-strange-shape%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I found a solution and wanted to let anyone having the same problem know.
    @Zephyr wasn't far off, however it was maxHeight but minHeight that created the problem. It has to be set to USE_PREF_SIZE in the SceneBuilder instead of USE_COMPUTED_SIZE wich seems to be the default value. After that simply change you prefSize in SceneBuilder's UI and everything works out great. The problem must have been the system failing to calculate the correct height on its own, for whatever reason, proably something to do with the font, because it didn't happen with any other fonts.






    share|improve this answer



























      0














      I found a solution and wanted to let anyone having the same problem know.
      @Zephyr wasn't far off, however it was maxHeight but minHeight that created the problem. It has to be set to USE_PREF_SIZE in the SceneBuilder instead of USE_COMPUTED_SIZE wich seems to be the default value. After that simply change you prefSize in SceneBuilder's UI and everything works out great. The problem must have been the system failing to calculate the correct height on its own, for whatever reason, proably something to do with the font, because it didn't happen with any other fonts.






      share|improve this answer

























        0












        0








        0







        I found a solution and wanted to let anyone having the same problem know.
        @Zephyr wasn't far off, however it was maxHeight but minHeight that created the problem. It has to be set to USE_PREF_SIZE in the SceneBuilder instead of USE_COMPUTED_SIZE wich seems to be the default value. After that simply change you prefSize in SceneBuilder's UI and everything works out great. The problem must have been the system failing to calculate the correct height on its own, for whatever reason, proably something to do with the font, because it didn't happen with any other fonts.






        share|improve this answer













        I found a solution and wanted to let anyone having the same problem know.
        @Zephyr wasn't far off, however it was maxHeight but minHeight that created the problem. It has to be set to USE_PREF_SIZE in the SceneBuilder instead of USE_COMPUTED_SIZE wich seems to be the default value. After that simply change you prefSize in SceneBuilder's UI and everything works out great. The problem must have been the system failing to calculate the correct height on its own, for whatever reason, proably something to do with the font, because it didn't happen with any other fonts.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 15:58









        SnuffduffSnuffduff

        63




        63





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288425%2fcreating-buttons-in-java-with-custom-font-causes-buttons-to-have-strange-shape%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Syphilis

            Darth Vader #20