I am trying to make a java desktop application where I am using multiple JLabel
I want to set fix height and width of JLabel
. How can I achieve thi
An easy work around (without overriding existing classes) is to;
Create a JPanel specifically for the component
Set the size for the JPanel
Place the component within the JPanel
Place the JPanel where you would have originally placed the component
e.g.
JPanel mainPanel = new JPanel(); //Assume this is the panel you are placing things into.
JLabel nameLabel = new JLabel("Name:");
JPanel nameLabelPanel = new JPanel();
nameLabelPanel.setPreferredSize(new Dimension(100, 25));
JPanel.add(nameLabel);
mainPanel.add(nameLabelPanel);