javax.swing.JLabel#getText ( )源码实例Demo

下面列出了javax.swing.JLabel#getText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ghidra   文件: ProgramContextMergeManagerTest.java
private void checkDisplayValues(Long latest, Long my, Long original) throws Exception {
	waitForPrompting();
	String latestExpected = getValueString(latest);
	String myExpected = getValueString(my);
	String originalExpected = getValueString(original);
	waitForPostedSwingRunnables();
	Window window = windowForComponent(getMergePanel());
	final VerticalChoicesPanel comp = findComponent(window, VerticalChoicesPanel.class);
	JLabel latestLabel = (JLabel) findComponentByName(comp, comp.getComponentName(1, 1));
	JLabel myLabel = (JLabel) findComponentByName(comp, comp.getComponentName(2, 1));
	JLabel originalLabel = (JLabel) findComponentByName(comp, comp.getComponentName(3, 1));
	String latestValue = latestLabel.getText();
	String myValue = myLabel.getText();
	String originalValue = originalLabel.getText();
	assertEquals(latestExpected, latestValue);
	assertEquals(myExpected, myValue);
	assertEquals(originalExpected, originalValue);
}
 
源代码2 项目: netbeans   文件: QueryTableCellRenderer.java
private static String computeFitText(JLabel label) {
    String text = label.getText();
    if(text == null) text = "";
    if (text.length() <= VISIBLE_START_CHARS + 3) return text;
    
    Icon icon = label.getIcon();
    int iconWidth = icon != null ? icon.getIconWidth() : 0;
    
    FontMetrics fm = label.getFontMetrics(label.getFont());
    int width = label.getSize().width - iconWidth;

    String sufix = "...";                                                   // NOI18N
    int sufixLength = fm.stringWidth(sufix);
    int desired = width - sufixLength;
    if (desired <= 0) return text;

    for (int i = 0; i <= text.length() - 1; i++) {
        String prefix = text.substring(0, i);
        int swidth = fm.stringWidth(prefix);
        if (swidth >= desired) {
            return prefix.length() > 0 ? prefix + sufix: text;
        }
    }
    return text;
}
 
源代码3 项目: visualvm   文件: RotateLabelUI.java
private String layout(JLabel label, FontMetrics fm, int width, int height) {
    Insets insets = label.getInsets(paintViewInsets);
    String text = label.getText();
    Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
    paintViewR.x = insets.left;
    paintViewR.y = insets.top;

    if (vertical) {
        paintViewR.height = width - (insets.left + insets.right);
        paintViewR.width = height - (insets.top + insets.bottom);
    } else {
        paintViewR.width = width - (insets.left + insets.right);
        paintViewR.height = height - (insets.top + insets.bottom);
    }

    paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
    paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
    return layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR);
}
 
源代码4 项目: pumpernickel   文件: ThumbnailLabelUI.java
protected void calculateGeometry(JLabel label) {
	FontMetrics fm = label.getFontMetrics(label.getFont());
	String text = label.getText();
	Icon icon = label.getIcon();
	int verticalAlignment = label.getVerticalAlignment();
	int horizontalAlignment = label.getHorizontalAlignment();
	int verticalTextPosition = label.getVerticalTextPosition();
	int horizontalTextPosition = label.getHorizontalTextPosition();
	int textIconGap = label.getIconTextGap();
	viewR.setFrame(0, 0, getViewWidth(label), label.getHeight());
	SwingUtilities.layoutCompoundLabel(fm, text, icon, verticalAlignment,
			horizontalAlignment, verticalTextPosition,
			horizontalTextPosition, viewR, iconRect, textRect, textIconGap);

	textRect.x = label.getWidth() / 2 - textRect.width / 2;
	iconRect.x = label.getWidth() / 2 - iconRect.width / 2;
	iconRect.y = 0;
	textRect.y = iconRect.height + label.getIconTextGap();
}
 
源代码5 项目: jclic   文件: AbstractBox.java
@Override
public Object clone() {
  AbstractBox bx = (AbstractBox) super.clone();
  if (specialShape)
    bx.shape = new Area(shape);
  else
    bx.shape = bx;
  if (hostedComponent != null) {
    if (hostedComponent instanceof JLabel) {
      JLabel lb = (JLabel) hostedComponent;
      bx.hostedComponent = new JLabel(lb.getText(), lb.getIcon(), lb.getHorizontalAlignment());
      JComponent jc = bx.getContainerResolve();
      if (jc != null)
        jc.add(hostedComponent);
    } else
      bx.hostedComponent = null;
  }
  return bx;
}
 
源代码6 项目: ghidra   文件: FunctionTagMergeTest.java
private int getTagConflictCount() throws Exception {
	VerticalChoicesPanel mergePanel = getMergePanel(VerticalChoicesPanel.class);
	assertNotNull(mergePanel);
	JLabel header = (JLabel) TestUtils.getInstanceField("headerLabel", mergePanel);
	String headerStr = header.getText();
	headerStr = headerStr.replaceAll("[^0-9]+", " ");
	String[] numbers = headerStr.trim().split(" ");
	if (numbers.length >= 2) {
		return Integer.valueOf(numbers[1]);
	}

	return -1;
}
 
源代码7 项目: ghidra   文件: CreateLabelsFromEnumsTest.java
private void checkStatusMessage(String expectedMessage) {
	PluginTool pluginTool = plugin.getTool();
	DockingWindowManager windowManager = pluginTool.getWindowManager();
	Object rootNode = TestUtils.invokeInstanceMethod("getRootNode", windowManager);
	StatusBar statusBar = (StatusBar) TestUtils.getInstanceField("statusBar", rootNode);
	JLabel statusLabel = (JLabel) TestUtils.getInstanceField("statusLabel", statusBar);
	String statusMessage = statusLabel.getText();
	assertEquals(expectedMessage, statusMessage);
}
 
源代码8 项目: marathonv5   文件: JavaElementPropertyAccessor.java
public String getLabeledBy() {
    if (getComponent() instanceof JComponent) {
        try {
            JLabel label = (JLabel) ((JComponent) getComponent()).getClientProperty("labeledBy");
            if (label != null && label.getText() != null && !label.getText().equals("")) {
                return stripLastColon(label.getText().trim());
            }
        } catch (ClassCastException e) {
        }
    }
    return null;
}
 
源代码9 项目: SmartIM   文件: ClosableTabHost.java
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);
    }
}
 
源代码10 项目: pumpernickel   文件: AquaThumbnailLabelUI.java
@Override
protected void paintText(Graphics2D g, JLabel label, String text,
		boolean isSelected, boolean isIndicated) {
	if (isSelected) {
		roundRect.setRoundRect(textRect.x - 4, textRect.y,
				textRect.width + 8, textRect.height, 16, 16);
		g.setColor(selectedTextBackground);
		g.fill(roundRect);
		g.setColor(Color.white);
	} else {
		g.setColor(Color.black);
	}
	super.paintText(g, label, label.getText(), isSelected, isIndicated);
}
 
源代码11 项目: dsworkbench   文件: BBCellRenderer.java
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    JLabel l = (JLabel) c;
    String text = l.getText();
    l.setText("<html><head>" + BBCodeFormatter.getStyles() + "</head><body><nobr>" + BBCodeFormatter.toHtml(text) + "</nobr></body></html>");
    l.setToolTipText("<html><head>" + BBCodeFormatter.getStyles() + "</head><body>" + BBCodeFormatter.toHtml(text) + "</body></html>");
    return l;
}
 
源代码12 项目: seaglass   文件: SeaGlassLabelUI.java
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException("Width and height must be >= 0");
    }
    JLabel label = (JLabel) c;
    String text = label.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = label.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SeaGlassContext context = getContext(label);
    FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(context, fm, label.getText(), label.getIcon(),
        label.getHorizontalAlignment(), label.getVerticalAlignment(), label.getHorizontalTextPosition(),
        label.getVerticalTextPosition(), viewRect, iconRect, textRect, label.getIconTextGap());
    View view = (View) label.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    } else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
 
源代码13 项目: osp   文件: DataTable.java
/**
 * Returns the rendered component.
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {      
	Component c = baseRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	if (c instanceof JLabel && units!=null) {
		JLabel label = (JLabel)c;
		if (label.getText()!=null && !label.getText().equals("")) //$NON-NLS-1$
			label.setText(label.getText()+units);
		label.setToolTipText(tooltip);
	}
	return c;
}
 
源代码14 项目: swing_library   文件: TableRowUtilities.java
/**
 * Adjusts the column width of the row headers table containg the number
 * column. The font metrics are extracted from the label of the row at the
 * bottom of the viewport and used to determing the appropriate width.
 * 
 * The reason why this method is important, is that when the row number increases by an extra digit
 * the column needs to get wider. It also needs to shrink when scrolling to smaller digit numbers.
 * 
 * @param rowHeadersTable - single column table in the row header
 * @param label - label used to get font metrics
 * @param scrollBarValue - int value for determing point of lowest row
 */
private static void adjustColumnWidth(final JTable rowHeadersTable, final JLabel label, int scrollBarValue) {
	
	label.setFont(rowHeadersTable.getFont());
	label.setOpaque(true);
	label.setHorizontalAlignment(JLabel.CENTER);

	int v = rowHeadersTable.getVisibleRect().height;

	int row = rowHeadersTable.rowAtPoint(new Point(0, v + scrollBarValue));

	Integer modelValue = null;
	if (row != -1) {
		modelValue = (Integer) rowHeadersTable.getModel().getValueAt(row, 0);
	} else {
		RowHeadersTableModel tm = (RowHeadersTableModel) rowHeadersTable.getModel();
		modelValue = new Integer(tm.getMaxIntValue());
	}

	label.setText("" + modelValue);
	FontMetrics fontMetrics = label.getFontMetrics(label.getFont());

	int widthFactor = 0;

	if (fontMetrics != null && label.getText() != null) {
		widthFactor = fontMetrics.stringWidth(label.getText());

		rowHeadersTable.setPreferredScrollableViewportSize(new Dimension(widthFactor + 8, 100)); // height
																									// is
																									// ignored
		rowHeadersTable.repaint();
	}
}
 
源代码15 项目: Spark   文件: GroupChatParticipantList.java
protected String getSelectedUser() {
	JLabel label = (JLabel) participantsList.getSelectedValue();
	if (label != null) {
		return label.getText();
	}

	return null;
}
 
源代码16 项目: slick2d-maven   文件: EmitterList.java
/**
 * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
 */
public Component getListCellRendererComponent(JList list, final Object value, int index, boolean isSelected, boolean cellHasFocus) {
	JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected,
			cellHasFocus);
	
	final JCheckBox box = new JCheckBox(label.getText());
	box.setBackground(label.getBackground());
	
	box.setSelected(((ConfigurableEmitter) value).isEnabled());
	checks.put(value, box);
	
	return box;
}
 
源代码17 项目: ghidra   文件: DefaultRowFilterTransformer.java
protected String getStringValue(ROW_OBJECT rowObject, int column) {
	// we have to account for 'magic' hidden columns
	if (columnModel instanceof GTableColumnModel) {
		if (!((GTableColumnModel) columnModel).isVisible(column)) {
			return null;
		}
	}

	if (columnUsesConstraintFilteringOnly(column)) {
		// This allows columns to be ignored for default text filtering while still being
		// filterable through the column constraints API
		return null;
	}

	// note: this call can be slow when columns dynamically calculate values from the database
	Object value = model.getColumnValueForRow(rowObject, column);
	if (value == null) {
		return null;
	}

	/*
	 	Methods for turning the cell value into a string to be filtered (in preference order):
	 		1) Use the dynamic column's renderer (if applicable), as this is the most
	 		   direct way for clients to specify the filter value
	 		2) See if the value is an instance of DisplayStringProvider, which describes how
	 		   it should be rendered
	 		3) See if it is a label (this is uncommon)
	 		4) Rely on the toString(); this works as intended for Strings.  This is the 
	 		   default way that built-in table cell renderers will generate display text
	 */

	// 1)
	String renderedString = getRenderedColumnValue(value, column);
	if (renderedString != null) {
		return renderedString;
	}

	// 2) special plug-in point where clients can specify a value object that can return 
	// its display string
	if (value instanceof DisplayStringProvider) {
		return ((DisplayStringProvider) value).toString();
	}

	// 3
	if (value instanceof JLabel) { // some models do this odd thing
		JLabel label = (JLabel) value;
		String valueString = label.getText();
		return valueString == null ? "" : valueString;
	}

	// 4)
	return value.toString();
}
 
源代码18 项目: netbeans   文件: StatusBar.java
public String getText(String cellName) {
    JLabel cell = getCellByName(cellName);
    return (cell != null) ? cell.getText() : null;
}
 
源代码19 项目: visualvm   文件: RotateLabelUI.java
public void paint(Graphics g, JComponent c) {
      JLabel label = (JLabel)c;
      String text = label.getText();
      Icon icon = label.isEnabled() ? label.getIcon() : label.getDisabledIcon();

      if (icon == null && text == null) return;

      Graphics2D g2 = (Graphics2D) g;
  	AffineTransform transform = null;

      if (rotation != ROTATE_0) {
          transform = g2.getTransform();
          g2.rotate(rotation);
          
          if (rotation == ROTATE_90) {
              g2.translate(0, -c.getWidth());
          } else if (rotation == ROTATE_180) {
              g2.translate(-c.getWidth(), -c.getHeight());
          } else if (rotation == ROTATE_270) {
              g2.translate(-c.getHeight(), 0);
          }
      }

      FontMetrics fm = g.getFontMetrics();
      String clippedText = layout(label, fm, c.getWidth(), c.getHeight());

      if (icon != null) icon.paintIcon(c, g, paintIconR.x, paintIconR.y);

      if (text != null) {
   View v = (View)c.getClientProperty(BasicHTML.propertyKey);
   if (v != null) {
v.paint(g, paintTextR);
   } else {
int textX = paintTextR.x;
int textY = paintTextR.y + fm.getAscent();

if (label.isEnabled()) {
    paintEnabledText(label, g, clippedText, textX, textY);
} else {
    paintDisabledText(label, g, clippedText, textX, textY);
}
   }
      }

      if (transform != null) g2.setTransform(transform);
  }
 
源代码20 项目: mars-sim   文件: VerticalLabelUI.java
@Override
   public void paint(Graphics g, JComponent c) {
       JLabel label = (JLabel)c;
       String text = label.getText();
       Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();

       if ((icon == null) && (text == null)) {
           return;
       }

       FontMetrics fm = g.getFontMetrics();
       paintViewInsets = c.getInsets(paintViewInsets);

       paintViewR.x = paintViewInsets.left;
       paintViewR.y = paintViewInsets.top;

   	// Use inverted height &amp; width
       paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
       paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

       paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
       paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;

       String clippedText = layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR);

   	Graphics2D g2 = (Graphics2D) g;
   	AffineTransform tr = g2.getTransform();
   	if (clockwise) {
           g2.rotate( Math.PI / 2 );
           g2.translate( 0, - c.getWidth() );
   	} else {
           g2.rotate( - Math.PI / 2 );
           g2.translate( - c.getHeight(), 0 );
   	}

   	if (icon != null) {
           icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
       }

       if (text != null) {
           int textX = paintTextR.x;
           int textY = paintTextR.y + fm.getAscent();

           if (label.isEnabled()) {
               paintEnabledText(label, g, clippedText, textX, textY);
           } else {
               paintDisabledText(label, g, clippedText, textX, textY);
           }
       }
g2.setTransform( tr );
   }