You are not logged in.

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

1

Tuesday, July 22nd 2014, 9:10pm

Questions about the bottom windows, in the IDE

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?

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

2

Tuesday, July 22nd 2014, 10:05pm

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?

It is standard error, and it's easy to direct it to a file with printstream and seterr. But I don't know how to direct it, to a component text area.

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

3

Wednesday, July 23rd 2014, 10:39am

Error - Exception - StackTrace

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

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

4

Wednesday, July 23rd 2014, 1:11pm

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

Thanks, Dani. I can do that, but I was trying to find out if there was a way to redirect the output, before it hits that window.

Anyway, it's no longer necessary. All set, thanks.

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

5

Wednesday, July 23rd 2014, 3:31pm

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

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

6

Wednesday, July 23rd 2014, 4:04pm

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.

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

7

Saturday, July 26th 2014, 8:00pm

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;

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

8

Saturday, July 26th 2014, 8:25pm

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;



Redirection to a file is straightforward, of course. I was using this, for the past several days:


'// DC, find a way to redirect this to a text box
'// psError = New PrintStream( "/download/test/ErrorStream.txt" )
'// #System.setOut( psError )
'// #System.setErr( psError )

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

9

Sunday, July 27th 2014, 1:53pm

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;




In
psError = New PrintStream( New clsOutputStream( frmJBClojure.txtOutput ) ),

it looks like Jabaco doesn't like the reference to the txtOutput object. It stops on the above statement.


Even if you simply try to get a reference to the frmJBClojure.txtOutput, thus,

Dim txtOut As VB#TextBox

or

Dim txtOut As Variant

txtOut = frmJBClojure.txtOutput

, it stops on the

txtOut = frmJBClojure.txtOutput

statement.

This post has been edited 1 times, last edit by "jbExplorer" (Jul 27th 2014, 2:34pm)


jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

10

Sunday, July 27th 2014, 2:41pm

Ugh. Stupid. It's in the middle of the form_load, so the child components haven't been fully defined yet.

Alright, please disregard all of the above. I'll start a new thread, with the solution to this question. But only after cutting the grass first.

Rate this thread
WoltLab Burning Board