jLabels automatically goes newline
I have some jlabels which works fine, but i need them to be "bold".So i used html to introduce strong tags. Now my text is bold but it goes newline when the end of the jlabel is reached instead of truncate it adding some end dots, like was before using html. Minimum, Maximum and Preferred size of jlabels are set to [80,14] and they are not resizeable.Here some code:
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")));
}
}
As you can see, lines 2 and 3 have the same text set but the bolded one goes newline. How to avoid this?
为什么不使用粗体字体而不使用HTML?
Font f = myLabel.getFont();
myLabel.setFont( new Font( f.getName(), Font.BOLD, f.getSize() ) );
链接地址: http://www.djcxy.com/p/88888.html
上一篇: 如何使用Jade HTML添加br标签
下一篇: jLabels自动换行