/** * Updates the number of unique trees matched and the number of total trees matched by the last * pattern that was searched for. Thread-safe. * * @param pattern The pattern * @param treeMatches count of unique trees matched by the pattern * @param totalMatches count of total matching instances */ public void updateFoundStats(final String pattern, final int treeMatches, final int totalMatches) { final String txt = "<html>Match stats: " + treeMatches + " unique trees found with " + totalMatches + " total matches.</html>"; SwingUtilities.invokeLater(() -> { foundStats.setPreferredSize(foundStats.getSize()); foundStats.setText(txt); if(pattern != null) addToHistoryList(pattern, treeMatches, totalMatches); }); }
private float originY(WrappedLines lines) { return (float) (label.getSize().getHeight() / 2.0 - lines.height / 2f); }
private float xFor(TextLayout line) { return (float) (label.getSize().getWidth() / 2.0 - line.getAdvance() / 2f); }
/** * Sets the minimum width of the coordinate display label and the format string used to print * values. */ private void setLabelSizeAndFormat() { int minLabelWidth = getStringWidth(); Dimension labelSize = label.getSize(); if (labelSize.width < minLabelWidth) { label.setMinimumSize(new Dimension(minLabelWidth, labelSize.height)); revalidate(); } StringBuilder sb = new StringBuilder(); sb.append("%").append(intLen).append(".").append(decLen).append("f, "); sb.append("%").append(intLen).append(".").append(decLen).append("f"); numFormat = sb.toString(); }
/** * Checks the current label width against its minimum width and, if the current width is larger, * adjusts the minimum to prevent the label growing and shrinking as the cursor is moved. */ private void ensureMinLabelWidth() { Dimension minDim = label.getMinimumSize(); Dimension curDim = label.getSize(); if (curDim.width > minDim.width) { label.setMinimumSize(new Dimension(curDim.width, minDim.height)); } } }
public ColorPanel(ColorComponent colorComponent) { this.colorComponent = colorComponent; setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); Dimension d = new Dimension(Integer.MAX_VALUE, 30); setMinimumSize(d); setPreferredSize(d); setMaximumSize(d); JLabel label = new JLabel(nodebox.util.StringUtils.humanizeName(colorComponent.toString().toLowerCase(Locale.US)), JLabel.RIGHT); Dimension size = label.getSize(); label.setFont(Theme.SMALL_BOLD_FONT); label.setForeground(new Color(66, 66, 66)); label.setPreferredSize(new Dimension(75, size.height)); label.setAlignmentY(JLabel.CENTER); label.setBorder(new EmptyBorder(3, 0, 0, 0)); add(label); add(Box.createHorizontalStrut(2)); draggableNumber = new DraggableNumber(); draggableNumber.addChangeListener(this); d = new Dimension(20, Integer.MAX_VALUE); draggableNumber.setPreferredSize(d); draggableNumber.setMaximumSize(d); draggableNumber.setSize(d); add(draggableNumber); slider = new ColorSlider(this); add(slider); add(Box.createHorizontalStrut(7)); }
private WrappedLines breakLines(Graphics2D g) { Dimension size = label.getSize(); float maxWidth = size.width; AttributedString attributedText = new AttributedString(label.getText(), textAttributes()); AttributedCharacterIterator textIterator = attributedText.getIterator(); FontRenderContext fontRendering = g.getFontRenderContext(); LineBreakMeasurer measurer = new LineBreakMeasurer(textIterator, fontRendering); WrappedLines lines = new WrappedLines(); while(measurer.getPosition() < textIterator.getEndIndex()) { TextLayout layout = measurer.nextLayout(maxWidth); lines.add(layout); } return lines; }
private ImagePreviewWorker(String imageFilePath, JLabel imageLabel) { this.imageFilePath = imageFilePath; this.imageLabel = imageLabel; this.targetDimension = this.imageLabel.getSize(); }
private ImagePreviewWorker(String imageFilePath, JLabel imageLabel) { this.imageFilePath = imageFilePath; this.imageLabel = imageLabel; this.targetDimension = this.imageLabel.getSize(); }
public void doLayout() { super.doLayout(); if (myLabel != null) { myErrorLabel.setBorder(BorderFactory.createEmptyBorder(0, myLabel.getSize().width, 0, 0)); } } }
private Dimension getPreviewSize(CRSEnvelope crsEnvelope) { Dimension preferredSize = messageLabel.getSize(); if (preferredSize.width == 0 || preferredSize.height == 0) { preferredSize = new Dimension(400, 200); } return getPreviewImageSize(preferredSize, crsEnvelope); }
private Dimension getPreviewSize(CRSEnvelope crsEnvelope) { Dimension preferredSize = messageLabel.getSize(); if (preferredSize.width == 0 || preferredSize.height == 0) { preferredSize = new Dimension(400, 200); } return getPreviewImageSize(preferredSize, crsEnvelope); }
public BlingTimer(Component tab, String name) { super(300, null); addActionListener(this); component = tab; if (component != null && component instanceof JPanel) { label = (JLabel) ((JPanel) component).getComponent(0); src = label.getText(); if (src == null || src.isEmpty()) { src = name; } d = label.getSize(); label.setPreferredSize(d); } }
JDialog dialog = new JDialog(); JLabel label = new JLabel("Test"); dialog.add(label); // pack(), setSize(), validate() in this order will // set sizes on all components as wished dialog.pack(); dialog.setSize(800, 600); dialog.validate(); System.out.println(label.getSize());
/** * Checks the current label width against its minimum width and, * if the current width is larger, adjusts the minimum to prevent * the label growing and shrinking as the cursor is moved. */ private void ensureMinLabelWidth() { Dimension minDim = label.getMinimumSize(); Dimension curDim = label.getSize(); if (curDim.width > minDim.width) { label.setMinimumSize(new Dimension(curDim.width, minDim.height)); } } }
/** * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) */ @Override protected void paintComponent(Graphics g) { boolean initStateSecondLine = panel.isInitStateSecondLine() && panel.isShowInitState(); Dimension s = name.getSize(); int th = (textHeight + 2) * (initStateSecondLine ? 2 : 1); backgroundImageLabel.renderLabel((Graphics2D) g, 0, (s.height - th) / 2, s.width, th); super.paintComponent(g); }