Bonjour tous le monde,
Je vous expliques brièvement la situation, j'ai trouvé un bout de code sur internet pour rediriger les logs vers un JTextArea jusqu'ici pas de soucis ça marche !
Sauf qu'au moment d'ajouter un JScrollPane car les logs peuvent être longue il apparaît à l'écran mais est pas fonctionnel du tout du tout j'ai beau cherché d'ou cela pourrait venir, aucune idée..
Ma ConsoleFrame ou je définis mon JFrame :
Ma ConsolePanel ou il y a tous ce qui est TextArea ScrollPane :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
45
46
47
48 package fr.kedarin.thamosLauncherv2.model; import javax.swing.JFrame; import fr.kedarin.thamosLauncherv2.view.ConsolePanel; import fr.theshark34.swinger.Swinger; import fr.theshark34.swinger.util.WindowMover; @SuppressWarnings("serial") public class ConsoleFrame extends JFrame{ private static ConsoleFrame instance; private ConsolePanel consolePanel; public ConsoleFrame() { this.setTitle("Thamos - Console Debug"); this.setSize(577, 425); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.setUndecorated(true); this.setIconImage(Swinger.getResource("icon.jpg")); consolePanel = new ConsolePanel(); this.setContentPane(consolePanel = new ConsolePanel()); WindowMover mover = new WindowMover(this); this.addMouseListener(mover); this.addMouseMotionListener(mover); this.setBackground(Swinger.TRANSPARENT); this.getContentPane().setBackground(Swinger.TRANSPARENT); this.setVisible(true); instance = this; } public static void option() { instance = new ConsoleFrame(); } public static ConsoleFrame getInstance() { return instance; } public ConsolePanel getConsolePanel() { return this.consolePanel; } }
Puis le TextAreaOutputStream ou je dis de rediriger les logs dans un JTextAerea :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
45
46
47
48
49
50
51
52
53
54
55
56
57 package fr.kedarin.thamosLauncherv2.view; import static fr.theshark34.swinger.Swinger.drawFullsizedImage; import static fr.theshark34.swinger.Swinger.getResource; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.io.PrintStream; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import fr.kedarin.thamosLauncherv2.controler.TextAreaOutputStream; @SuppressWarnings("serial") public class ConsolePanel extends JPanel { //Background private Image background = getResource("backgroundconsole.png"); // Text Area private JTextArea txtConsole = new JTextArea(); private JScrollPane scrolltxtPane = new JScrollPane(txtConsole); public ConsolePanel() { this.setLayout(null); // Config JTextArea scrolltxtPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); txtConsole.setBounds(0, 52, 555, 425); txtConsole.setEditable(false); txtConsole.setVisible(true); // Afficher les logs Launcher dans le JTextArea PrintStream out = new PrintStream( new TextAreaOutputStream( txtConsole ) ); System.setOut( out ); System.setErr( out ); // JScrollPane scrolltxtPane.setBounds(555, 52, 22, 375); scrolltxtPane.getViewport().setBackground(Color.WHITE); // Add au panel this.add(txtConsole); this.add(scrolltxtPane); } @Override public void paintComponent(Graphics graphics) { super.paintComponent(graphics); drawFullsizedImage(graphics, this, background); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
45
46
47
48
49
50
51
52 package fr.kedarin.thamosLauncherv2.controler; /* * * @(#) TextAreaOutputStream.java * */ import java.io.IOException; import java.io.OutputStream; import javax.swing.JTextArea; /** * An output stream that writes its output to a javax.swing.JTextArea * control. * * @author Ranganath Kini * @see javax.swing.JTextArea */ public class TextAreaOutputStream extends OutputStream { private JTextArea textControl; /** * Creates a new instance of TextAreaOutputStream which writes * to the specified instance of javax.swing.JTextArea control. * * @param control A reference to the javax.swing.JTextArea * control to which the output must be redirected * to. */ public TextAreaOutputStream( JTextArea control ) { textControl = control; } /** * Writes the specified byte as a character to the * javax.swing.JTextArea. * * @param b The byte to be written as character to the * JTextArea. */ public void write( int b ) throws IOException { // append the data as characters to the JTextArea control textControl.append( String.valueOf( ( char )b ) ); } public JTextArea getTextControl() { return textControl; } }
Merci à vous![]()
Partager