11/9/2023 0 Comments Netbeans increase font sizeJava font size methods comes from JTextComponentĪs mentioned, I'm using this code with a JTextPane but the getFont and setFont methods both come from the JTextComponent class, so I expect this same approach would work with the JTextField JTextArea and JEditorPane classes as well. As you can imagine, the code is identical, except I increment the font size by one instead of decrementing it. It's also worth mentioning that I have a similar method that increases the text area font size. (Although the JTextPane has many more font features, I'm just creating a simple text editor, so I'm only using one font at a time in the text editing area.) This changes the font for the entire JTextPane, which is what I want. ![]() I create the Font f2 by using that font information, but making the font size one size smaller.I get the current font from the JTextPane.Java smaller font size action - discussionĪs you can see from that code, I do the following things: create a new, smaller font from the current fontįont f2 = new Font(f.getFontName(), f.getStyle(), f.getSize()-1) * Reduce the size of the font in the JTextPane editor area. ![]() I didn't expect this to be easy, but I've been pleasantly surprised that the following approach seems to work just fine: /** I'm currently writing a customized text editor in Java, and as part of that, I want to make it easy for the user to increase or decrease the font size in the text editing area (technically a JTextPane). How do I change the font size of a g or g2d drawstring object First create your g (or g2d) drawstring object String string 'Hello World' then create a Font object Font stringFont new Font ( 'SansSerif', Font.PLAIN, 18 ) Next set the Font object to the g or g2d object g2d.setFont ( stringFont ) Now apply the g2d (or g) object to your.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |