Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
Hi,
The bottom right window, the one that contains 'Listening for transport', and any errors - that's the standard error, correct?
Is there an official Jabaco method for redirecting this, to a text box?
Jabaco Source |
|
1 2 3 4 5 6 7 |
'Import java#util#Arrays Dim Stack() As String, i As Integer Stack = Split(Arrays.toString(Err.getStackTrace()),",") For i = 0 To Ubound(Stack) Debug.Print Stack(i) Next i |
Hey there,
if you want to access the StackTrace:
Jabaco Source
1 2 3 4 5 6 7 'Import java#util#Arrays Dim Stack() As String, i As Integer Stack = Split(Arrays.toString(Err.getStackTrace()),",") For i = 0 To Ubound(Stack) Debug.Print Stack(i) Next i
Dani
but I was trying to find out if there was a way to redirect the output, before it hits that window.
but I was trying to find out if there was a way to redirect the output, before it hits that window.
If you found a solution, please do share your code!
Thanks
Dani
Of course, will do.
Source code |
|
1 2 |
Public psError As PrintStream psError = New PrintStream( New clsOutputStream( frmJBClojure.txtOutput ) ) |
Source code |
|
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 |
Import java#io#OutputStream Import javax#swing#JTextArea Import java#io#IOException Import VB#TextBox Dim txtArea As JTextArea Dim txtJBTextArea As VB#TextBox Public Sub clsOutputStream( txtJB As VB#TextBox ) txtArea = Cast( txtJB, JTextArea ) End Sub Public Sub write( nOutputCharacter As Integer ) Dim cOutputCharacter As String cOutputCharacter = Chr( nOutputCharacter ) txtJBTextArea.AppendText( cOutputCharacter ) '// txtArea.append( cOutputCharacter ) '// txtArea.setCaretPosition( txtArea.getDocument().getLength() ) End Sub |
but I was trying to find out if there was a way to redirect the output, before it hits that window.
If you found a solution, please do share your code!
Thanks
Dani
Of course, will do.
Dani,
I'm converting a Java example, and will share the code when it's finished.
Can a VB#TextBox be cast, as a JTextArea?
I'm sublcassing OutputStream, and one of the parameters is a JTextArea instance.
So, in the form load, we have
Source code
1 2 Public psError As PrintStream psError = New PrintStream( New clsOutputStream( frmJBClojure.txtOutput ) )
In the Class module clsOutputStream, we have
Source code
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 Import java#io#OutputStream Import javax#swing#JTextArea Import java#io#IOException Import VB#TextBox Dim txtArea As JTextArea Dim txtJBTextArea As VB#TextBox Public Sub clsOutputStream( txtJB As VB#TextBox ) txtArea = Cast( txtJB, JTextArea ) End Sub Public Sub write( nOutputCharacter As Integer ) Dim cOutputCharacter As String cOutputCharacter = Chr( nOutputCharacter ) txtJBTextArea.AppendText( cOutputCharacter ) '// txtArea.append( cOutputCharacter ) '// txtArea.setCaretPosition( txtArea.getDocument().getLength() ) End Sub
This is taken from
http://www.codejava.net/java-se/swing/re…ms-to-jtextarea
:
The main idea is based on the two methods provided by the System class:
◦System.setOut(PrintStream): Re-assigns the standard output stream.
◦System.setErr(PrintStream): Re-assigns the standard error output stream.
Create a sub class of OutputStream class like this:
package net.codejava.swing;
import java.io.IOException;
import java.io.OutputStream;
import javax.swing.JTextArea;
/**
* This class extends from OutputStream to redirect output to a JTextArrea
* @author www.codejava.net
*
*/
public class CustomOutputStream extends OutputStream {
private JTextArea textArea;
public CustomOutputStream(JTextArea textArea) {
this.textArea = textArea;
}
@Override
public void write(int b) throws IOException {
// redirects data to the text area
textArea.append(String.valueOf((char)b));
// scrolls the text area to the end of data
textArea.setCaretPosition(textArea.getDocument().getLength());
}
}
As we can see, the constructor takes a JTextArea object as argument and overrides the write(int) method from the OutputStream class. In the write() method, we convert the byte to a character and append it to the JTextArea. So everything written to this output stream will be placed into the text area. Then we can re-assign the standard output streams as follows:
JTextArea textArea = new JTextArea(50, 10);
PrintStream printStream = new PrintStream(new CustomOutputStream(textArea));
System.setOut(printStream);
System.setErr(printStream);
If we still want to use the standard output streams, we have to keep references to them before re-assigning, for example:
PrintStream standardOut = System.out;
PrintStream standardErr = System.err;
but I was trying to find out if there was a way to redirect the output, before it hits that window.
If you found a solution, please do share your code!
Thanks
Dani
Of course, will do.
Dani,
I'm converting a Java example, and will share the code when it's finished.
Can a VB#TextBox be cast, as a JTextArea?
I'm sublcassing OutputStream, and one of the parameters is a JTextArea instance.
So, in the form load, we have
Source code
1 2 Public psError As PrintStream psError = New PrintStream( New clsOutputStream( frmJBClojure.txtOutput ) )
In the Class module clsOutputStream, we have
Source code
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 Import java#io#OutputStream Import javax#swing#JTextArea Import java#io#IOException Import VB#TextBox Dim txtArea As JTextArea Dim txtJBTextArea As VB#TextBox Public Sub clsOutputStream( txtJB As VB#TextBox ) txtArea = Cast( txtJB, JTextArea ) End Sub Public Sub write( nOutputCharacter As Integer ) Dim cOutputCharacter As String cOutputCharacter = Chr( nOutputCharacter ) txtJBTextArea.AppendText( cOutputCharacter ) '// txtArea.append( cOutputCharacter ) '// txtArea.setCaretPosition( txtArea.getDocument().getLength() ) End Sub
This is taken from
http://www.codejava.net/java-se/swing/re…ms-to-jtextarea
:
The main idea is based on the two methods provided by the System class:
◦System.setOut(PrintStream): Re-assigns the standard output stream.
◦System.setErr(PrintStream): Re-assigns the standard error output stream.
Create a sub class of OutputStream class like this:
package net.codejava.swing;
import java.io.IOException;
import java.io.OutputStream;
import javax.swing.JTextArea;
/**
* This class extends from OutputStream to redirect output to a JTextArrea
* @author www.codejava.net
*
*/
public class CustomOutputStream extends OutputStream {
private JTextArea textArea;
public CustomOutputStream(JTextArea textArea) {
this.textArea = textArea;
}
@Override
public void write(int b) throws IOException {
// redirects data to the text area
textArea.append(String.valueOf((char)b));
// scrolls the text area to the end of data
textArea.setCaretPosition(textArea.getDocument().getLength());
}
}
As we can see, the constructor takes a JTextArea object as argument and overrides the write(int) method from the OutputStream class. In the write() method, we convert the byte to a character and append it to the JTextArea. So everything written to this output stream will be placed into the text area. Then we can re-assign the standard output streams as follows:
JTextArea textArea = new JTextArea(50, 10);
PrintStream printStream = new PrintStream(new CustomOutputStream(textArea));
System.setOut(printStream);
System.setErr(printStream);
If we still want to use the standard output streams, we have to keep references to them before re-assigning, for example:
PrintStream standardOut = System.out;
PrintStream standardErr = System.err;
This post has been edited 1 times, last edit by "jbExplorer" (Jul 27th 2014, 2:34pm)