【发布时间】:2015-07-20 14:41:11
【问题描述】:
我有一些工作正常的 jlabels,但我需要它们“大胆”。所以我使用 html 来引入强标签。现在我的文本是粗体的,但是当到达 jlabel 的末尾时它会换行而不是截断它添加一些结束点,就像使用 html 之前一样。 jlabels 的最小、最大和首选大小设置为 [80,14] 并且它们不可调整大小。这里有一些代码:
public PanelArchivio(Lavoro lavoro) {
//Nimbus ha un bug che riguarda il colore di sfondo dei textpanel e altri pannelli di testo
//Creo il colore e lo metto di default al background dei textpane
Color bgColor = new Color(255, 255, 153);
UIDefaults defaults = new UIDefaults();
defaults.put("TextPane[Enabled].backgroundPainter", bgColor);
initComponents();
this.lavoro = lavoro;
jLabel_Cod.setText("<html><strong>"+this.lavoro.getCodice()+"</strong></html>");
jLabel_DataCons.setText("<html><strong>"+Integer.toString(this.lavoro.getDataCons().getDate())+"/"+Integer.toString(this.lavoro.getDataCons().getMonth())+"/"+Integer.toString(this.lavoro.getDataCons().getYear())+"</strong></html>");
if(this.lavoro.getOp1().equals(""))
jLabel_Op1.setText("");
else
jLabel_Op1.setText("<html><strong>"+this.lavoro.getOp1()+"</strong></html>");
if(this.lavoro.getOp2().equals(""))
jLabel_Op2.setText("");
else
jLabel_Op2.setText(this.lavoro.getOp3());
if(this.lavoro.getOp3().equals(""))
jLabel_Op3.setText("");
else
jLabel_Op3.setText("<html><strong>"+this.lavoro.getOp3()+"</strong></html>");
jTextArea_Note.setText(this.lavoro.getNote());
jTextArea_Note.setLineWrap(true);
jTextArea_Note.setCaretPosition(0);
String ThumbnailPath = "C:/DecoLedisApp/Media/Disegni/Thumbnails/"+this.lavoro.getCodice()+".png";
//Se il percorso è corretto setto il Thumbnail, altrimenti setto un immagine di default
try {
File f = new File(ThumbnailPath);
if (f.exists() && !f.isDirectory()) {
//Faccio un flush dell'immagine caricata, evitando che java
//utilizzi l'immagine in cache senza ricaricare il file
ImageIcon FlushedIcon = new ImageIcon(ThumbnailPath);
FlushedIcon.getImage().flush();
jLabel_Thumbnail.setIcon(FlushedIcon);
} else {
jLabel_Thumbnail.setIcon(new ImageIcon(PanelModOperatore.class.getResource("/Images/EmptyThumbnail.png")));
}
} catch (NullPointerException e) {
jLabel_Thumbnail.setIcon(new ImageIcon(PanelModOperatore.class.getResource("/Images/EmptyThumbnail.png")));
}
}
如您所见,第 2 行和第 3 行具有相同的文本集,但粗体部分是换行符。 如何避免这种情况?
【问题讨论】:
-
"这里有一些代码:" 请注意,MCVE/SSCCE 不是“一些代码”,而是一种非常特殊的代码形式。请点击链接并阅读相关内容。
-
添加了更多信息。现在应该清楚了
-
无法编译的代码 sn-p。由于您显然没有阅读我提供的链接,因此我认为这是“研究不足”并获得反对票。