setPreferredSizewill really change the size of the label, which you should just try to draw using the method setBorderto check the new size, but the font size has not changed, if you want the large font to try to call setFontand set a new font size, here to start, enter the code:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;
public class Test {
public static void main(String[] args) {
JFrame t = new JFrame();
t.setBounds(100, 100, 500, 400);
JLabel l = new JLabel("Hello");
l.setFont(new Font(l.getFont().getName(), l.getFont().getStyle(), 20));
l.setBorder(new LineBorder(Color.BLACK));
l.setPreferredSize(new Dimension(200, 200));
t.getContentPane().setLayout(new FlowLayout());
t.add(l);
t.setVisible(true);
}
}
source
share