-1
我有一些jlabels工作正常,但我需要他們是「大膽」。所以我用html來介紹強標籤。現在我的文本是粗體的,但是當到達jlabel的末尾時它會換行,而不是截斷它添加一些末端點,就像在使用html之前一樣。最小,的JLabel最高和首選的大小設置爲[80,14],他們不resizeable.Here一些代碼:jLabels自動去換行
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具有相同的文字集,而加粗一個去換行。 如何避免這種情況?
爲什麼GUI不使用佈局? 1)爲了更快地獲得更好的幫助,請發佈[MCVE](http://stackoverflow.com/help/mcve)(最小完整可驗證示例)或[SSCCE](http://www.sscce.org/)(簡稱,自包含,正確的例子)。 2)以最小尺寸提供ASCII藝術或簡單的GUI圖形*圖形,並且如果可調整大小,則具有更大的寬度和高度。 –
*「Here some code:」*請注意,MCVE/SSCCE不是'某些代碼',而是非常特定的代碼形式。請按照鏈接並閱讀它。 –
更多信息已添加。現在應該清楚 – Razinar