Java Utililty Methods JLabel Size

List of utility methods to do JLabel Size

Description

The list of methods to do JLabel Size are organized into topic(s).

Method

voidadjustLabelSizes(List labels)
Adjusts the label sizes.
Dimension max;
max = new Dimension(0, 0);
for (JLabel label : labels) {
    if (max.getWidth() < label.getPreferredSize().getWidth())
        max = label.getPreferredSize();
for (JLabel label : labels)
    label.setPreferredSize(max);
...
DimensiongetLabelPreferredSize(JLabel label)
Returns the preferred size for a label.
return getLabelPreferredSize(label, "Sample text");
DimensiongetPreferredLabelSize(JLabel c, int widthHint)
get Preferred Label Size
View v = (View) c.getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey);
if (v == null) {
    return c.getPreferredSize();
String text = c.getText();
Icon icon = c.isEnabled() ? c.getIcon() : c.getDisabledIcon();
int hAlign = c.getHorizontalAlignment();
int vAlign = c.getVerticalAlignment();
...
DimensiongetPreferredSize(JLabel label)
get Preferred Size
if (label == null) {
    throw new IllegalArgumentException("label==null");
Dimension preferredSize = null;
Dimension dm = getTextDimension(label);
dm = extendByIcon(label, dm);
dm = extendByBorder(label, dm);
preferredSize = dm;
...
voidmakeSameSize(int alignment, JLabel... labels)
make Same Size
makeSameSize(labels);
for (JLabel label : labels) {
    label.setHorizontalAlignment(alignment);
voidresizeLabel(JLabel label, Dimension newDim)
resize Label
label.setPreferredSize(newDim);