Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Jimmy Nilsson

+ Follow
since Sep 25, 2004
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jimmy Nilsson

Thanks, dident notice that with the maximum, ofcourse i shold use that one.

17 years ago

I need to get the maximum posible scrool position of a JScrollbar

The getMaximum() simes to work fine!

But the getVlaue is not as good. When i print out all the getvalues as soon as i move the scrool i have notice that when the scrool is in the top, the value is never 0, insted its 10-20 ?

And when the Scrool bar is at the bottom it shold be the sam value that the getMaximum, but insted there can be a big diffrent, say Maximum = 5300 and the value at the buttom is about 4200-4600 ??

Is there any way to get a more specified values for the scrollers position?

17 years ago

I have Two JTextPanes that may contain diffrent amopunt of text. To this JTextPane i have JScroolPanes.

I Want the ScroolPanes to be syncroniced and when scroll1 is on location 75% then Scroll2 shold also be on the 75%.

I have problem with doing the math of this, the variabels dont simes to be abled to save fractions?


double tmpMScrool = scrollbar1.getVerticalScrollBar().getValue();
double tmpMScroolMax = scrollbar1.getVerticalScrollBar().getMaximum();

double ScrollCount = (double)tmpMScrool/(double)tmpMScroolMax;

ScrollCount = (double)scrollbar2.getVerticalScrollBar().getValue() * (double)ScrollCount;

//After this the ScrollCount is 0???


What is the problem here?

Best Regards
17 years ago
Yes i use JScrollbars, exacly as i do to the JPane, but in the jpane i can set the preferedsize and the horizontal jscoolbar will be activated, this does not wokr in JTextPane.

I have tryed before to set values to the JScroolbar but this wount work, maby you could show me?

As i said, i can get the vertical scroolbars active by adding text but to activet the hrozontal whene there is no text simes hard?

17 years ago

I have a JTextPane that i have added som text in, this text is to the left, by this i dont get the horizontal scrollbara available.

I am drawing some drwaings in this JTextPane and need to be abled to scrool horizontal to see all the drawings.

How do i do this? i know that JPane have a prefersize witch works fine, but JTextPane does not respond on this method?

How do i solve this?

17 years ago
Hey, i got a problem!

I have one class:
public class DocumentFrame extends JInternalFrame implements ActionListener

this class holds newdoc and olddoc

In the contructer its creates a object of an internal class:
public class drawPanel extends javax.swing.JPanel implements AdjustmentListener

this internal class overrides the JPane Paint method and draws the New doc by hand.

In main i have the folowing code:
_documentSplitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, _documentNewFrame, _documentOldFrame);

bouth the newFrame and the OldFrame contain NEW doc and OLD DOC, but in _documentNewFrame the New doc is the master(the real new doc) and in _documentOldFrame the New doc is the slave(the old doc).

i also have the following code to add them to screen:
_treedocSplitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, _tabbedframe, _documentSplitpane);


and then i add the treedocSplitpane to the Window.

This works almost perfect, there is a problem i cant solve.

When open the window the master(_documentNewFrame) is drawing its doc to the left and the slave((_documentoldFrame) is drawing to the right.

This looks good, but when running on a XWindow with slo update i notice that thay switches places to draw in? documentoldFrame is drawing to the left and so on? when loading the docs it looks good but when scrooling thay are jumping from drawing in the left to the right and so on. The result is not looking to good.

Shold not this deside where it shold be drawing?
_documentSplitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, _documentNewFrame, _documentOldFrame);

Hope you understand it?

17 years ago

Here is how it works

The Solaris machine is running a server program that makes it possible for all computers on the company with a surtain client program (Windows - Exceed) to connect to the Solaris machine.

When connected to the Solaris machine this client (Exceed) is displaying a graphic interface of Solaris on the PC.

My Program is a plug-in to one of the available programs on the Solaris machine; this program gives my program the input data (the chosen documents).

With other words: my program is located on the Solaris machine/server.

I could make a server program on the Solaris machine that opens up a version of my program on the client (in Windows) and shows the information. But I really think that the company wants that everything should be displayed in this Solaris/Windows client(Exceed) . Even if it�s okay I don�t know how I could build a application like this?, and how all the company computers could get my software installed automatically. But it would help a lot, the printing problem in Solaris would work fine in Windows.

About the JDK version, I know that they are not running the newest version of the JDK on the Solaris machine, but I think its 1.4 or something so it should work?

And they will not update the JDK version be course there is many programs that they believe will fail to work.

I am as you know, using Swing right now, but maybe SWT should work better? If I choose my way with SWT, how complex is it to use? I only have 1 week to get this program to work in Solaris, and am not use to work with java and Solaris(as you probably have notice).

Again I am thankful for a detailed information about how I could make this work, I have tried a lot of ways and have no id�e left how I could get it to work.

17 years ago

I have tryed to print out the text manual as you say by using Graphics.drawString(TEXT)

But this takes alot of preformance, the JText Pane most have some special algorithms to show the text, problely not .drawString (or .drawtext?)

or is there anything i am missing?

I have also tryed to draw the content to a bitmap file and then show this bitmap file, but then i have to devide the pages so i dont get BIG bitmaps.

Pleas any sugestions at all?

17 years ago

I have develop a program in Windows and it works fine there! now i have to move it over to Solaris, there have been alot of problems doing this!

The program is supose to show defferences between two docs(own format) this docs can contain Tabels, text, digrams and alot more.

The problem have been the to display the document with the differences markt in colors.

firs i tryued to use graphics.drawtext and .drawLine and so on. This workt fine one the windows computer but in solaris it hade big preformance problems. I notice that the .drawstring took alot of preformance so i desided to display the text by creating a styled document and then add this to a JTextPane, but i also hade to over ride Paintcomponent to be abled to paint the tables, diagrams and so on. this version is showing good preformance in solaris and windows.

But there is still alot of problems.
when changing size on the text and reloading the page it is not changing the siplay size in solaris(works in Windows)

The text is not marked all the way out on the right side, and if i select the text with the mouse the text that is not makrt is becoming white as the background.

Is there anything i am missing here? why is this not working in solaris when it works so well in Windows? Maby there is another way to display my text, diagrams and so on in Solaris with out this problems?

The Docs could look like this



texttexttexttexttext Drawings to the text
text Drawings to the text

texttexttext table to the text
text table to the text
textvtexttexttext table to the text
texttexttext table to the text


I have workt along time on this problem and would be wary GLAD if someone have the time to help me.

17 years ago
A note: this problem only accure on Solaris, in Windows it works fine.

17 years ago

I Creates a Styled document, and marks some words. Every line is ended with a \n.

To add my text to the styleddocument i use
Styleddocument.insertString(this.getLength(), " " + pt.getStr(),
this.getStyle("" + pt.getCol()));

The a add this Styled dokument to the JTextPane by

There will be colors, but the problem is that it is not coloring all the way out on the right side? and if i mark the text by drag the mouse pointer over and puch the button to select som text it will be selected, but that part of the text on the right side that was not colored is not visible at all?

Maby not to god explanation, but plesa try to help me on this one, this is my 3d try to display text repetly.

17 years ago

How do i turn off the WordWrap in TysledDokument and JTextPane?

17 years ago
Hey again!

by overridering this in JTextPane

public void setBounds(int x, int y,int width, int height)

Dimension size = this.getPreferredSize();
,1000+Math.max(size.width, width)


i get the horixontal scroller like i whant, but if i try to scroll it just jumps back on place 0 again?

ples help

17 years ago

I have a JTextPane that loads a DefaultStyledDocument.

Every row in this Styeld Document is ending with a "\n". To the right of this text i am drawing(overrides the paint method).

I have set a scroll that is visible bouth as vertical and horizontal. Now it is only using the vertical scroller to be abled to scrool down and see the text. But i realy need it to be abled to scrool vertical to see the drawings.

Is there any way? maby i can set the size on the Styleddocument? i cant set the size on the JTextPane i think?

17 years ago

I have a JTextPane that i loads with text, and then i draw some darwings on it.

The text i am adding is lie this

"There is no row that dont stops with\n"
"And here is anotherone\n"

this means that the text will not resize dynamic. I realy have to be abled to scroll side ways(as big as the page is horizontal. Is there nay way to do this?

17 years ago