
com.jidesoft.swing.MultilineLabel Maven / Gradle / Ivy
/*
* @(#)MultilineLabel.java
*
* Copyright 2002 JIDE Software. All rights reserved.
*/
package com.jidesoft.swing;
import javax.swing.*;
import javax.swing.text.DefaultCaret;
import java.awt.*;
/**
* Normal JLabel cannot have multiple lines. If you want to multiple
* label, you can use this class.
*/
public class MultilineLabel extends JTextArea {
public MultilineLabel() {
initComponents();
}
public MultilineLabel(String s) {
super(s);
initComponents();
}
private void initComponents() {
adjustUI();
}
/**
* Reloads the pluggable UI. The key used to fetch the
* new interface is getUIClassID()
. The type of
* the UI is TextUI
. invalidate
* is called after setting the UI.
*/
@Override
public void updateUI() {
super.updateUI();
adjustUI();
}
/**
* Adjusts UI to make sure it looks like a label instead of a text area.
*/
protected void adjustUI() {
setLineWrap(true);
setWrapStyleWord(true);
setEditable(false);
setRequestFocusEnabled(false);
setFocusable(false);
setOpaque(false);
setCaret(new DefaultCaret() {
@Override
protected void adjustVisibility(Rectangle nloc) {
}
});
LookAndFeel.installBorder(this, "Label.border");
LookAndFeel.installColorsAndFont(this, "Label.background", "Label.foreground", "Label.font");
}
/**
* Overrides getMinimumSize
to return getPreferredSize()
instead.
* We did this because of a bug at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4824261.
*
* @return the preferred size as minimum size.
*/
@Override
public Dimension getMinimumSize() {
return getPreferredSize();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy