1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
public ErrorPanel() {
//initilisation
//definition des style d'ecriture
StyleContext styleContext = new StyleContext();
redStyle = styleContext.addStyle(null,null);
StyleConstants.setForeground( redStyle, Color.red);
greenStyle = styleContext.addStyle(null,null);
StyleConstants.setForeground( greenStyle, Color.green);
doc = new DefaultStyledDocument( styleContext );
textError = new JTextPane( doc );
textError.setEnabled( false );
JScrollPane scrollBar = new JScrollPane( textError );
scrollBar.setPreferredSize( new Dimension( 690, 80 ) );
this.add( scrollBar );
}
//affiche les erreurs/information par rapport aux fichiers
public void fctPrintError( String result ) {
//information message in green
if( result.startsWith( "Erreur" ) ) {
try {
textError.setText( "" );
doc.insertString( 0, result, redStyle );
}
catch( BadLocationException e ) {
System.out.println( "Erreur" );
}
}
//error message in red
else {
try {
textError.setText( "" );
doc.insertString( 0,result, greenStyle );
}
catch( BadLocationException e ) {
System.out.println( "Erreur" );
}
}
} |
Partager