I have seen similar questions such as this, but in my case I have 25+ private JLabels that I give a value for when I declare it. I use a GridBagLayout in my constructor to add these JLabels to a JPanel. If I use something along the lines of the answer given in the link, it will only change JLabels that were added in the constructor.
So it seems to me that if I want to change the font size of my private JLabels, I would have to either define the font size for them individually, or change the default in my constructor and then add my JLabels. However, I am sure that there must be another, simpler way, but I just don't have the experience or understanding to figure it out, or to make proper adjustments from answers to other similar questions.
I don' think that this really requires me to show my code, but if it helps I can do so.
public class LaborRecordPanel implements
Printable, ActionListener {
private Color shade = new Color(201,201,201);
private ImageIcon logoIcon = new ImageIcon("Images/fici_logo1.jpg");
private JLabel logoLabel = new JLabel(logoIcon);
private JLabel authorizedBy = new JLabel("AUTHORIZED BY:");
private JLabel toCertify = new JLabel("THIS IS TO CERTIFY THAT THE ABOVE LABOR HAS BEEN PERFORMED.");
private JLabel laborRecordNO = new JLabel("NO.");
private JLabel nameOfJob = new JLabel("NAME OF JOB:");
private JLabel customerPO = new JLabel("CUSTOMER PO #:");
private JLabel contractNO = new JLabel("CONTRACT NO.");
private JLabel weekEnding = new JLabel("WEEK ENDING");
private JComboBox laborRateDescription = new JComboBox();
//...
JPanel rp = new JPanel();
JScrollPane scrollPane = new JScrollPane(rp);
LaborRecordPanel(){
//Font oldLabelFont = UIManager.getFont("Label.font");
//UIManager.put("Label.font",oldLabelFont.deriveFont(Font.PLAIN));
//UIManager.put("Label.font", UIManager.getFont("Label.font").deriveFont(40));
//SwingUtilities.updateComponentTreeUI(rp);
rp.setPreferredSize(new Dimension(1295,1830 ));
scrollPane.getVerticalScrollBar().setUnitIncrement(16); //increase the scroll speed
GridBagLayout gridbag = new GridBagLayout();
rp.setBackground(Color.WHITE);
rp.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
GridBagConstraints gbc = new GridBagConstraints();
rp.setLayout(gridbag);
//gbc.insets = new Insets(5, 5, 5, 5);
//row 0////////////////////////////////////////////////////////////
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 10;
gbc.gridy = 0;
gbc.weightx = 1;
gbc.weighty = 1;
gbc.gridheight = 1;
gbc.gridwidth = 1;
laborRecordNO.setHorizontalAlignment(JLabel.CENTER);
laborRecordNO.setFont(new Font("Dialog", Font.PLAIN, 18));
gridbag.setConstraints(laborRecordNO, gbc);
rp.add(laborRecordNO, gbc);
//row 1////////////////////////////////////////////////////////////
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 13;
gridbag.setConstraints(logoLabel, gbc);
rp.add(logoLabel, gbc);
//row 2////////////////////////////////////////////////////////////
gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridheight = 1;
gbc.gridwidth = 1;
gridbag.setConstraints(nameOfJob, gbc);
rp.add(nameOfJob, gbc);
gbc.gridx = 6;
gbc.gridy = 2;
gbc.gridheight = 1;
gbc.gridwidth = 3;
gridbag.setConstraints(contractNO, gbc);
rp.add(contractNO, gbc);
//... more setting constraints and adding
}
}