Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding Scrollbar for Applet contains more that 5000 lines  RSS feed

 
Ganesh kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to add scroll bar for a applet contains more than 5000 lines.I added the jscroll pane and set the preferred size 100000. I am able to see nearly only 1500 entries.I am not sure how to associate a scroll bar to applet to see all the lines added in applet.Appreciate the hellp.Thank you.

Code
----

[ December 26, 2008: Message edited by: Rayner ]
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recommend avoiding "magic" numbers with use of constants and using the information available to you to help set your proper size:

[ December 26, 2008: Message edited by: pete stein ]
 
Ganesh kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Thank you Rob Prime.I will use the code tags here after.

pete stein thank you very much for that reply.I am now able to see the all the lines.I am new to java and i will use the constants as you mentioned in the post.

I have one more doubt.My requiremt is to design a applet which should draw the lines (the line is a packet transmission).When i click particular line i have to show some information on tooltip.The range of line get displayed could be 100 to 90000.I am using applet beacause it has to be viewable in both the browser and the application.My question is whether i have yo use jpane or canvas.Which one suits the above requirement in a better way.Thank you.

Regards
Ganesh M
[ December 26, 2008: Message edited by: Rayner ]
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rayner:
I have one more doubt.My requiremt is to design a applet which should draw the lines (the line is a packet transmission).When i click particular line i have to show some information on tooltip.The range of line get displayed could be 100 to 90000.I am using applet beacause it has to be viewable in both the browser and the application.My question is whether i have yo use jpane or canvas.Which one suits the above requirement in a better way.


I think that Swing (JPanel, JApplet, JFrame) is much more robust than AWT (Canvas, Applet, Frame), and thus Swing is the way to go. I recommend that you do everything in a JPanel and that the JApplet class be nothing more than a driver class that places the main JPanel in JApplet's contentPane. Your JScrollPane will hold a JPanel, and you may wish that this inner JPanel use GridLayout(0, 1) (1 column, many rows) to hold many rows of a JComponent (this could be JLabel, or JPanel , or JWhatever), each with it's tooltip set properly.
 
Ganesh kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pete stein,I will try with what you have suggested.Thank you.

Regards
Ganesh M
 
Ganesh kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Now i have progressed with the Jpanel and JApplet.Its working fine.In my case i have to do some calculation for string parsing to get some information need to be displayed along with the lines while i am drawing.This work fine for 500 to 1000 line.If it crosses above 4000 lines it slows down the application.Usually the expected line may range from 4000 to 50000.

It seems that for every scrolling it redraws the complete set of lines again.Instead of doing so is it possible to draw a specific region based on the scroll bar movement.Kindly recommend some good way of doing this.
Thanks in advance.

Regards
Ganesh
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This suggests to me that you are doing something very costly in terms of CPU and time from within a paint or paintComponent method. Perhaps you need to adjust this: either limit your painting to that which is visible, or (and this is what I prefer) use separate components such as a JLabel or JPanel array and do painting within each component of the array when needed.

If these suggestions don't help you, you may want to post a small compilable program that demonstrates what you are trying to do and what problems you are having. This is called an SSCCE and information on how to create one can be found here:
SSCCE -- Short, Self Contained, Correct (Compilable), Example
 
Ganesh kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pete stein once again thanks for the reply.I was out for vacation leave.Thats why i am not able to reply soon.
Thanks for your suggestion.Now i have optimized the code for painting which works fine.The acutal problem was
the i had stored the information in hashmap,In paint procedure call i removed all the entries and once again stored the
structure.

Regards
Ganesh M
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!