Stanislav Lapitsky

Ranch Hand
+ Follow
since Dec 01, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Stanislav Lapitsky

luca rossix wrote:Hello friends,

i'm doing a spell checker, but i have a problem with a JTextPane.

I want to insert te checked text into a JTextPane where all the recognized wrong words have to be clickable like a button. When clikked (simple click) they should list all the possible correction into a JList just below the JTextPane.

Some idea on how to do it? Expecially what listener should i use?

EDIT: Offcourse the Jlist and the JTextPane are on the some jpanel on a jframe.



Use normal MouseListener to listen clicks. Then obtain offset of clicked point by viewToModel() method. Then use Utilities.getWordStart() getWordEnd() to detect bounds of the clicked word. The find somehow suggestions for the word and place them in the list.
6 years ago
They have to share model somehow. In case of JTextComponents the model is Document. And you have to kind of serialize the document. E.g. write to HTML for HTMLEditorKit and restore it reading from HTML to documnet.
6 years ago
Try to use a profiler (e.g. JProfiler) to understand what instances of what classes aren't removed. Then see how they appear in you app. Where they created and why. Is there any way to reuse or free them.
6 years ago
It's possible by custom GlyphPainter. See for example http://java-sl.com/gp_effects.html
You can use the same approach to enlarge space only.
6 years ago
I would say you need one highlighter/painter which will decide how to draw particular highlight. Also it should manage all the highlights addings/removing and merge/split highlights if necessary. I don't think overlaping highlights is a good idea. If you have the overlap just break existing highlights or create a migger one and remove inner highlights.
6 years ago
Actually foreground color (if specified) is used to render the text. May be you can try to set it before selection painting and reset after.
6 years ago
What about JTextComponent.setSelectedTextColor()?
Take a look at the GlyphView.public void paint(Graphics g, Shape a) method source


As you can see the color is used if the SwingUtilities2.useSelectedTextColor(highlight, tc) is true.
6 years ago
There might be a leak in PlainDocument class (JTextArea uses). Try to replace this

with
7 years ago
How do you create the icon? Guess from a file. But if you pack all the classes and resources in a jar file you can't acess image file.
Try to use

and then create image from the stream.
7 years ago
On press button start a timer with reasonable delay. In the timer action check pressed state. If the button still pressed show your popup. On release action stop the timer.
7 years ago
I have no simple answer. My solution supposes one level children pagination. It means if you list item contains several paragraphs and sum of heights of the paragraphs is bigger than page height the list item isn't split. In other words the pagination doesn't split nested elements.
So all you need is to create custom view for lists. The view should check list items heights and shift list items to the next page. If you need more complicated logic my simple example should be extended to adress the same pagination to nested elements.
7 years ago
My suggestion is the same. Write the same functionality as for paragraphs for ListView.
Hierarchy is
BlockView (e.g. body)
ListView
ListItemView
ParagraphView

If you replace paragraph or list item views ListView remains the same block which can't be split.
7 years ago
1) I think all you need is to pass a flag to the root view you have. E.g. via document.properties or directly to rootView. textPane.getUI().getRootView() and down to the necessary view. The view should check the flag and do your paginated layout or the original layout.

2)For the list view and guess for the table view you need to write something similar to ParagraphView. An algorithm to move children based on the pagination info you have from parent.

Actually the ListView and tableView extend the same BoxView so noting difficult to write the same code.
7 years ago