0

I am making a calculator and I want to make it that way that when the user's input reaches 26(inputs,so when he types 26 numbers,high unlikely but whatever) that the font of the JTextField will go from 18 to 14, so that more numbers can fit in the JTextField. Any ideas how can i achive that? I would like it to use the if-statement. As I am a beginner at programming I would like the solutionl. I saw another question almost similar but that question was about changing the font when a certain chatacter was entered so please don't mark this as duplicate.

to be simple as possible:p thank you for taking time for this!

I have this but it does not work;

  private void TextFieldOutputActionPerformed(java.awt.event.ActionEvent evt) {                                                
    if (TextFieldOutput.getText().length()> 26){
        Font font=new Font("Arial", Font.BOLD,12);
           TextFieldOutput.setFont(font);
    }
}    
henk_bae
  • 25
  • 7
  • 1
    have a look at this: http://stackoverflow.com/questions/12737829/javafx-textfield-resize-to-text-length – Shreyas Sarvothama Oct 21 '16 at 14:27
  • If I understood it correctly, that post is about the Jtextfield adjusting its size depending on how many words the user has typed. – henk_bae Oct 21 '16 at 14:33
  • Yes.. isnt it what you need? – Shreyas Sarvothama Oct 21 '16 at 14:35
  • No, I want the JtextField to stay the same size and the font to get smaller when the user has typed a certain amount of numbers – henk_bae Oct 21 '16 at 14:37
  • ok look at this code: http://www.java-examples.com/change-font-jtextfield-example when textField.getText().length() in listener method is 26 you can change the field object font to waht ever you want as shown in the above example – Shreyas Sarvothama Oct 21 '16 at 14:42
  • I updated the question with what I have but it does not work,thanks for the link tho!. – henk_bae Oct 21 '16 at 15:06
  • does it even enter your if condition.. try debugging.. first check whether listener/action performed is working or not.. put a simple log or println to check whether is it even responding – Shreyas Sarvothama Oct 21 '16 at 15:07

1 Answers1

0

You can add a listner to the JTextField and on that listener change the font object.

Please let me know if you need a small working code on this.

Rahul Singh
  • 19,030
  • 11
  • 64
  • 86
  • Hey! I am a beginner and not very good at this so if you can provide a working code that would be awesome!:) – henk_bae Oct 21 '16 at 15:20
  • I will provide it as soon as i reach my system, you can take a look at this link and my answer its not the whole picture bit will give you a idea. http://stackoverflow.com/questions/40179528/move-to-next-scene-page-with-just-pressing-a-number/40179850#40179850 – Rahul Singh Oct 21 '16 at 15:24