Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying text  RSS feed

 
Robert Fry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a Java applet telnet client, and the socket stuff is done now, but I'm trying to rig it so that the Swing component that displays the text displays it correctly.

Because it seems to use HTML as a default it does things like collapse multiple spaces down to a single space, ignore the telnet ANSI colour codes, that sort of thing.

I need to try and add this stuff in, but don't really have much idea of how that can be done. The Document interface doesn't look like its relevant to this, as it seems to be concerned more about the structure than how it looks - those extra spaces are in there, as it looks fine when output to the console instead of the JTextArea. The problem is how it looks.

I've been told this is quite easy, so I think I must be missing something fundamental here?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

I'm confused by your comment on HTML - Telnet most certainly does not use HTML for anything. It just transfers characters, so it shouldn't be too hard to append those to a JTextArea if you already have the transmission stuff working. (You'll also have to handle things like backspace/delete, of course.) Can you elaborate on what exactly are you struggling with?

Maybe you can get some inspiration from an existing open source Telnet client, like the one in the Apache Commons Net library.
 
Robert Fry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for answering.

Originally posted by Ulf Dittmer:
I'm confused by your comment on HTML - Telnet most certainly does not use HTML for anything. It just transfers characters, so it shouldn't be too hard to append those to a JTextArea if you already have the transmission stuff working. (You'll also have to handle things like backspace/delete, of course.) Can you elaborate on what exactly are you struggling with?


Well... I've already got the connection stuff all handled. There are two JTextAreas, one for input, one for the display, and the connection stuff seems to work just fine. Backspacing and stuff is done within the JTextArea, and when you hit 'enter' it fires it all off over the socket to the server in one go, and it seems to work.

It isnt the telnet bit that uses HTML, it looks like Swing uses it by default. unfortunately the server is not spitting HTML back!

The problem is making the text look nice on the screen, so two spaces are rendered as two spaces (the JTextArea seems to condense them down to one space, and I want it output literally as the server produces it), and also I need the telnet ANSI colour codes in there so the text is coloured. Its all about rendering it on the screen essentially.

I'm not sure how to proceed on it - I could tokenise the stream somehow before it reaches the JTextArea, or change the Swing component itself to render it correctly? I assume that changing the component is the way to do this, but... not sure.

Maybe you can get some inspiration from an existing open source Telnet client, like the one in the Apache Commons Net library.[/QB]


Well, I have had a look but the telnet apps seem to be mostly concerned with the connection itself, not the display of what the connection is spitting out at you.
 
Robert Fry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha, I have found one which has some sort of display panel which processes the text. I will look at that and maybe report back.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is making the text look nice on the screen, so two spaces are rendered as two spaces (the JTextArea seems to condense them down to one space, and I want it output literally as the server produces it), and also I need the telnet ANSI colour codes in there so the text is coloured. Its all about rendering it on the screen essentially.

Swing itself doesn't change anything you put into text component (like JTextArea). Maybe you're using a proportional font for which spaces are small compared to printing characters?

Here's an example of how to display colored text in Swing. It uses a JTextPane instead of a JTextArea, but the two are kind of similar, so you should be able to make that work.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!