Suppose I have the string "Hello World". I want to change the style of this line to a BOLD font and set the size of all characters from 12 to 18 [pt]. After that, I want to use this line in JLabeland JButton. How can i do this?
JLabel
JButton
Take a look here http://docs.oracle.com/javase/6/docs/api/java/awt/Font.html#deriveFont%28float%29
JComponent has a setFont () method. You will control the font there, not the String.
For instance,
JButton b = new JButton(); b.setFont(b.getFont().deriveFont(18.0f));
Font myFont = new Font("Serif", Font.BOLD, 12);, then use the setFont method for your components, for example
Font myFont = new Font("Serif", Font.BOLD, 12);
JButton b = new JButton("Hello World"); b.setFont(myFont);