You would need to call setFont(...)
not setStyle.
For example, if you want to keep the same font but change the style of a JTextField called "field" you could do something like:
field.setFont(field.getFont().deriveFont(Font.BOLD));
Edit
To set the font to both bold and italic, you'd or the bitmaps:
field.setFont(field.getFont().deriveFont(Font.BOLD | Font.ITALIC));
Please note that this uses the bitwise inclusive OR operator which uses a single pipe symbol: |
rather than the logical OR operator which uses a double pipe symbol: ||
.
Also note for further subtlety and confusion that |
can be used as a logical OR operator, but you'll usually prefer to use ||
for this since the latter is a "short-circuit" operator in that if the left hand side of the expression is true, the right hand side isn't even evaluated.