List of usage examples for javax.swing JLabel getSize
public Dimension getSize()
From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java
/** * Determines real size of HTML label with text on screen. * * @param html text with html markup/*w w w .j a v a 2s. com*/ * @return size of label */ public static Dimension measureHtmlText(String html) { JFrame testFrame = new JFrame(); testFrame.setLayout(new BoxLayout(testFrame.getContentPane(), BoxLayout.PAGE_AXIS)); JLabel testLabel = new JLabel(html); testFrame.add(testLabel); testFrame.pack(); Dimension size = testLabel.getSize(); testFrame.dispose(); return new Dimension(size); }
From source file:org.dwfa.ace.classifier.CNFormsLabelPanel.java
private void setBorder(JLabel tLabel, Color deltaColor) { if (deltaColor == null) { deltaColor = Color.white; }//from w w w.ja va 2s. c o m Dimension size = tLabel.getSize(); tLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 5, 1, 5, deltaColor), BorderFactory.createEmptyBorder(1, 3, 1, 3)))); size.width = size.width + 18; size.height = size.height + 6; tLabel.setSize(size); tLabel.setPreferredSize(size); tLabel.setMaximumSize(size); tLabel.setMinimumSize(size); }