I created a file .txt
which contains a sentence.
I want to set a Jlabel with this sentence and a picture .gif
So I did this :
(I declared 2 Strings with the path to my .txt and the path to my picture)
Then I asked to set it:
{
ZoneAlerte1 = new JLabel();
getContentPane().add(ZoneAlerte1);
ZoneAlerte1.setText(new UTIL_LireFichierTXT().getText(MessageTest));
ZoneAlerte1.setFont(new java.awt.Font("Tahoma",0,12));
ZoneAlerte1.setIcon(new ImageIcon(Icon));
ZoneAlerte1.setBounds(400, 200, 300, 40);
ZoneAlerte1.setVisible(true);
}
The thing is: when I run my programm, the Label contains the picture and my text but there's a little square between them, like if there were some unknown character in my sentence.
So I tried to replace this line:
ZoneAlerte1.setText(new UTIL_LireFichierTXT().getText(MessageTest));
by ZoneAlerte1.setText("hello");
And it works perfectly, without the square
Then I guess the problem comes from this method called to read a .txt :
public class UTIL_LireFichierTXT {
public String chaine="";
public String fichier ="";
public static void main(String[] args){
}
public String getText(String path){
fichier=path;
//lecture du fichier texte
try
{
InputStream ips=new FileInputStream(fichier);
InputStreamReader ipsr=new InputStreamReader(ips);
BufferedReader br=new BufferedReader(ipsr);
String ligne;
while ((ligne=br.readLine())!=null)
{
//System.out.println(ligne);
chaine+=ligne+"\n";
}
br.close();
//System.out.println(chaine);
return chaine;
}
catch (Exception e)
{
}
return chaine;
}
}
The problem doesn't come from my .txt or the label because when I do the exact same thing (setting my text without setting in a picture), it works without a square.
Actually it's pretty strange because:
Jlabel
+ this method to set .txt
: no square
Jlabel
+ picture + this method: square
Jlabel
+ picture: no square
Jlabel
+ picture + set.Text("Hello!")
: square
Thanks in advance.
PS : I used a Jlabel
instead of a JTextPane
because I needeed transparency.