I have a drawString()
method in my paintComponent
method. Is there a way to make the text drawn by the drawString()
bold? Also, is there a way to make the text bigger? I would like to avoid using JLabel
s, unless it is absolutely necessary.
DrawString(String, Font, Brush, Single, Single, StringFormat) Draws the specified text string at the specified location with the specified Brush and Font objects using the formatting attributes of the specified StringFormat.
void drawString(String str, int x, int y) The drawString() method, shown below, takes as parameters an instance of the String class containing the text to be drawn, and two integer values specifying the coordinates where the text should start.
Select the text that you want to make bold, and do one of the following: 1 Move your pointer to the Mini toolbar above your selection and click Bold Bold icon . 2 Click Bold Bold icon in the Font group on the Home tab. 3 Type the keyboard shortcut: CTRL+B. See More...
No, this is not possible. The DrawString function is going to draw all of the text you specify using the formatting flags that you specify. It's an all-or-nothing affair. If you want to make some portions bold and other portions not, then you will need to make multiple calls to the DrawString function.
Click “Copy” at the top right of the Output box or copy the formatted text manually by right clicking or pressing “CTRL + C” to copy the text to your clipboard. Go to Facebook.com and enter whatever text you want to have that’s not bold.
How to make a font thinner in Illustrator? You can make a font thinner using the same method as bold text. Create Outline > Effect > Offset Path . Change the number to negative, and your font will be thinner. Bold is beautiful and powerful. You can either use it to catch attention or as graphic background and design element.
According to documentation of drawString
:
Draws the text given by the specified string, using this graphics context's current font and color. The baseline of the leftmost character is at position (x, y) in this graphics context's coordinate system
Indeed, Graphics
class has the setFont(Font font)
method available:
g.setFont(new Font("default", Font.BOLD, 16));
You have to set the font before drawing the text.
g.setFont(font);
There are methods: setFont(Font) - Method in class java.awt.Component Sets the font of this component. setFont(Font) - Method in class java.awt.Container Sets the font of this container. setFont(Font) - Method in class java.awt.Graphics Sets this graphics context's font to the specified font.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With