Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JEditorPane Not Working  RSS feed

 
Sameera Abeysinghe
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to show color text on my application (each word in different color)
So I use following code


I have commented lines show the ways I tried

My code compiles and runs without errors
But in the window there is nothing shown on the jEditorpane
What am I doing wrong ?

I don�t think I can use JTextPane because I have to put images also
Can i use JTextPane ?

If some one can give me a working code that will be a big help

Thank You
 
Brian Cole
Author
Ranch Hand
Posts: 936
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's plenty in your code that I
wouldn't be happy with [why the null
layout manager? why the ungainly
jScrollPane1.getViewport().add()?]
but the text "hi Test" should be
shown in lavender on your JEditorPane.

And, since you asked, yes a JTextPane
can show images. Take a look at this
example from O'Reilly's Swing book.
 
Sameera Abeysinghe
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the reply

I want to put colored text and images at the same time. Can I do it in a textpane just like in the editorpane

And can u tell me y me code is not working?

I am using J2SDK 1.5 update 5
So I hope this has nothing to do with the version.
Right?

----------------------------------------------------
why the ungainly
jScrollPane1.getViewport().add()?]
----------------------------------------------------
What did u mean by this
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as why your code doesn't work: the main() routine says

new Testa().setVisible(true);

creating an instance of a class "Testa", but the class main() is actually is called "Test". Maybe you've got another class lying around named "Testa", and if so, it's that one that's being shown on the screen, not the code we're looking at here!

As far as the "jScrollPane1.getViewport().add()" problem, normally, what you do is

jScrollPanel = new JScrollPane(jEditorPane);

Although calling add() on the viewport works, I guess, it's "weird". It's not something normally done. Likewise the null layout manager. IN fact, there's all sorts of weird stuff about this code. That's probably because it was either generated by a GUI builder, or copied from code that was. GUI builders, almost by definition, generate horrible code -- you should never use it as an example of how to write "real" code yourself!
 
Brian Cole
Author
Ranch Hand
Posts: 936
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sameera Abeysinghe:
----------------------------------------------------
why the ungainly
jScrollPane1.getViewport().add()?
----------------------------------------------------
What did u mean by this


Well your code does this:

jScrollPane1 = new JScrollPane();
jEditorPane1 = new JEditorPane();
jScrollPane1.getViewport().add(jEditorPane1);

which is pretty weird, even though it does seem to work.
I'm not sure why even a code-generating tool would do it
that way. More normal would be this:

jScrollPane1 = new JScrollPane();
jEditorPane1 = new JEditorPane();
jScrollPane1.setViewportView(jEditorPane1);

or this:

jEditorPane1 = new JEditorPane();
jScrollPane1 = new JScrollPane(jEditorPane1);
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!