Java Utililty Methods JLabel

List of utility methods to do JLabel

  1. HOME
  2. Java
  3. J
  4. JLabel

Description

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

Method

void addMessageLogger(JLabel t)
Add the given component into the list of components that show messages from the message method calls
messageLogs.add(t);
void addParameterRow(Container container, JLabel label, Component component)
Add a label-value pair to a container that uses GridBagLayout.
GridBagLayout gridbag = null;
try {
 gridbag = (GridBagLayout) (container.getLayout());
} catch (Exception e) {
 System.err
 .println("Hey! You called addRow with" + " a container that doesn't " + " use GridBagLayout!");
 return;
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(0, 5, 0, 5);
gridbag.setConstraints(label, c);
container.add(label);
c.gridwidth = GridBagConstraints.REMAINDER;
c.weightx = 1.0;
gridbag.setConstraints(component, c);
container.add(component);
void clear(JLabel... fields)
clear
for (JLabel field : fields) {
 field.setText("");
void ensureCustomBackgroundStored(JLabel comp)
ensure Custom Background Stored
if (getStoredBackground(comp) != null)
 return;
Color background = comp.getBackground();
if ((background == null) || (background instanceof UIResource) || (background == WARNING_BACKGROUND)
 || (background == ERROR_BACKGROUND))
 return;
comp.putClientProperty(STORED_BACKGROUND_KEY, background);
void exibeMensagemTemporaria(final JLabel lblMensagem, String mensagem)
exibe Mensagem Temporaria
lblMensagem.setText(mensagem);
timer = new Timer(4 * 1000, new ActionListener() {
 public void actionPerformed(ActionEvent event) {
 timer.stop();
 lblMensagem.setText("");
});
timer.start();
...
Dimension extendByIcon(JLabel label, Dimension dm)
extend By Icon
if (label == null) {
 throw new IllegalArgumentException("label==null");
if (dm == null) {
 throw new IllegalArgumentException("dm==null");
javax.swing.Icon icon = label.getIcon();
if (icon == null)
...
int findMaxLabelWidth(JLabel... jLabels)
find Max Label Width
int maxvalue = 0;
for (JLabel label : jLabels) {
 FontMetrics fm = label.getFontMetrics(label.getFont());
 int width = fm.stringWidth(label.getText());
 if (maxvalue < width) {
 maxvalue = width;
return maxvalue;
String getLabelValue(JLabel lbl)
get Label Value
String ret = lbl.getText().trim();
if (!ret.equals("")) {
 return ret;
return null;
void getRoughStroke(final JLabel _jlbl_stroke)
Apply stroke on background.
final int strokeDistance = 20;
if (_jlbl_stroke.getWidth() > 0 && _jlbl_stroke.getHeight() > 0
) {
 BufferedImage bi_stroke = new BufferedImage(_jlbl_stroke.getWidth(), _jlbl_stroke.getHeight(),
 BufferedImage.TYPE_INT_ARGB);
 for (int x = 0; x < bi_stroke.getWidth(); x++) {
 for (int y = 0; y < bi_stroke.getHeight(); y++) {
 if ((x + y) % strokeDistance == 0) {
...
Color getStoredBackground(JLabel comp)
get Stored Background
return (Color) comp.getClientProperty(STORED_BACKGROUND_KEY);


AltStyle によって変換されたページ (->オリジナル) /