Java Code Examples for javax.swing.JLabel.getText()

The following are Jave code examples for showing how to use getText() of the javax.swing.JLabel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Proyecto-DASI   File: VisorCreacionEscenarios1.java   View Source Code Vote up 7 votes
public void actualizarCoordenadasEntidades(){
    System.out.println( "Se actualizan las coordenadas. Numero de entidades : "+listaEntidadesEnEscenario.size());
    int numRobots= 0; int numVictims= 0;
    for (JLabel entidadLabel : listaEntidadesEnEscenario) {
        String identEntidad = entidadLabel.getText();
        if (identEntidad.contains("Robot")||identEntidad.contains("robot")){
            escenarioActualComp.addRoboLoc(identEntidad, entidadLabel.getLocation());
            numRobots++;
        }
        else if (identEntidad.contains("Victim")){
            escenarioActualComp.addVictimLoc(identEntidad, entidadLabel.getLocation());
            numVictims++;
        }
        System.out.println( "Se actualiza la entidad : "+identEntidad+ " Coordenadas : X =" + entidadLabel.getX() +" , Y = " +entidadLabel.getY() );
        System.out.println( "Robots y victimas despues de la actualizacion. Num Robots :  "+numRobots+ " Num Victimas : " + numVictims );
    }
    escenarioActualComp.setNumRobots(numRobots);
    escenarioActualComp.setNumVictimas(numVictims);
   System.out.println( "Robots y victimas despues de la actualizacion. Num Robots :  "+escenarioActualComp.getNumRobots()+ " Num Vicitimas : " + escenarioActualComp.getNumVictimas() );
}
 
Example 2
Project: incubator-netbeans   File: QueryTableCellRenderer.java   View Source Code Vote up 6 votes
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;
}
 
Example 3
Project: trashjam2017   File: EmitterList.java   View Source Code Vote up 5 votes
/**
 * @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;
}
 
Example 4
Project: marathonv5   File: JavaElementPropertyAccessor.java   View Source Code Vote up 5 votes
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;
}
 
Example 5
Project: Progetto-C   File: EmitterList.java   View Source Code Vote up 5 votes
/**
 * @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;
}
 
Example 6
Project: JDigitalSimulator   File: Guitilities.java   View Source Code Vote up 5 votes
public static void setFittingLabelSize(JLabel label, int width) {
	int wordWidth, lines=1, size=0;
	if(width<=0||label.getText().isEmpty())
		return;
	StringTokenizer words = new StringTokenizer(label.getText());
	FontMetrics metrics = label.getFontMetrics(label.getFont());
	while(words.hasMoreTokens())
		if((size+=(wordWidth=metrics.stringWidth(words.nextToken())))>width) {
			size = wordWidth;
			lines++;
		}
	label.setPreferredSize(new Dimension(width, lines*metrics.getHeight()));
	label.revalidate();
}
 
Example 7
Project: Equella   File: UserDetailsPanel.java   View Source Code Vote up 5 votes
void clearErrors()
{
	for( JLabel label : labels.values() )
	{
		String t = label.getText();
		if( t.endsWith("*") ) //$NON-NLS-1$
		{
			label.setText(t.substring(0, t.length() - 1));
		}
	}
}
 
Example 8
Project: gchisto   File: StatusLabelManager.java   View Source Code Vote up 5 votes
/**
 * It creates a new status label manager instance.
 *
 * @param statusLabel The label to be managed.
 */
public StatusLabelManager(JLabel statusLabel) {
    ArgumentChecking.notNull(statusLabel, "statusLabel");
    
    this.statusLabel = statusLabel;
    this.originalText = statusLabel.getText();
    this.originalIsOpaque = statusLabel.isOpaque();
    this.originalFGColor = statusLabel.getForeground();
    this.originalBGColor = statusLabel.getBackground();
    updateTimeStamp();
    
    new Thread(new Deamon(this)).start();
}
 
Example 9
Project: incubator-netbeans   File: StatusBar.java   View Source Code Vote up 4 votes
public String getText(String cellName) {
    JLabel cell = getCellByName(cellName);
    return (cell != null) ? cell.getText() : null;
}