本文整理匯總了Java中javax.swing.JLabel.getText方法的典型用法代碼示例。如果您正苦於以下問題:Java JLabel.getText方法的具體用法?Java JLabel.getText怎麽用?Java JLabel.getText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JLabel
的用法示例。
在下文中一共展示了JLabel.getText方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: actualizarCoordenadasEntidades
import javax.swing.JLabel; //導入方法依賴的package包/類
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() );
}
示例2: computeFitText
import javax.swing.JLabel; //導入方法依賴的package包/類
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: getListCellRendererComponent
import javax.swing.JLabel; //導入方法依賴的package包/類
/**
* @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;
}
示例4: getLabeledBy
import javax.swing.JLabel; //導入方法依賴的package包/類
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;
}
示例5: setFittingLabelSize
import javax.swing.JLabel; //導入方法依賴的package包/類
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();
}
示例6: clearErrors
import javax.swing.JLabel; //導入方法依賴的package包/類
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));
}
}
}
示例7: StatusLabelManager
import javax.swing.JLabel; //導入方法依賴的package包/類
/**
* 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();
}
示例8: getText
import javax.swing.JLabel; //導入方法依賴的package包/類
public String getText(String cellName) {
JLabel cell = getCellByName(cellName);
return (cell != null) ? cell.getText() : null;
}