File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Want to add Horizontal and vertical scroll bar in my code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Want to add Horizontal and vertical scroll bar in my code" Watch "Want to add Horizontal and vertical scroll bar in my code" New topic
Author

Want to add Horizontal and vertical scroll bar in my code

Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Here is my code :


I want that Horizontal and vertical scroll bar should be added automatically.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

1. Why are you using AWT? Swing's been around for more than 10 years now.
2. If you must use AWT, check out the API for ScrollPane.
3. Better, use Swing and follow the links to relevant tutorial from the API for JScrollPane. Also, change your code to do custom painting in an extended JPanel or JComponent, following the guidelines in the tutorial on Performing Custom Painting, and respect Swing's single threaded rule, for which refer to the tutorial on Concurrency in Swing. And don't use getGraphics() of a component.


luck, db
There are no new questions, but there may be new answers.
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Darryl Burke wrote:1. Why are you using AWT? Swing's been around for more than 10 years now.
2. If you must use AWT, check out the API for ScrollPane.
3. Better, use Swing and follow the links to relevant tutorial from the API for JScrollPane. Also, change your code to do custom painting in an extended JPanel or JComponent, following the guidelines in the tutorial on Performing Custom Painting, and respect Swing's single threaded rule, for which refer to the tutorial on Concurrency in Swing. And don't use getGraphics() of a component.


I am new to Swing.
I want to draw hexagons and also want to add scrollpane in window
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I want to draw hexagons and also want to add scrollpane in window

please enlighten us as to what part of Darryl's reply you cannot understand.
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Michael Dunn wrote:> I want to draw hexagons and also want to add scrollpane in window

please enlighten us as to what part of Darryl's reply you cannot understand.


As per Darryl's reply I have to search for JScrollPane and JComponent.

I could find a airtcle in which they have show how to use JScrollPane and also draw custom shapes in JScrollPane using Graphics Object.

I want to draw custome shapes and also want scrollpane in same Panel but i could not find any solution for the same.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Have you really never referred to the API?
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Darryl Burke wrote:Have you really never referred to the API?


I have gone through those API, But Can i know how to draw a custom shape in JFrame and I also want ScrollPane in JFrame. ?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Darryl's reply explains the drawing bit.
Do you need it in braille?
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Michael Dunn wrote:Darryl's reply explains the drawing bit.
Do you need it in braille?


I have created Two files

Points.java



and another file named
CustomPanel.java



I do get ScrollPane but it is not scrolling by resizing JFrame.




[Thumbnail for Untitled.png]

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
the component in the scrolllPane needs to have a preferredSize larger than the scrollPane.
as your CustomPanel has no components, its preferredSize will be 0,0

add a constructor to CustomPanel

where 800,600 is anything you want
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Michael Dunn wrote:the component in the scrolllPane needs to have a preferredSize larger than the scrollPane.
as your CustomPanel has no components, its preferredSize will be 0,0

add a constructor to CustomPanel

where 800,600 is anything you want

I got scrollpane in it, but now problem is that If I do any changes in output window means GUI (like: Resize the window, Activating a window, minimizing or maximizing a window ) , at that time paintComponent of CustomPanel() are re initiated and they are drawn again.
How can i stop that ?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
paintComponent is called numerous times, for numerous reasons, and you don't want to stop it.

sounds more like there's a problem in your code.
Parth Pateld
Greenhorn

Joined: Nov 01, 2011
Posts: 29
Michael Dunn wrote:paintComponent is called numerous times, for numerous reasons, and you don't want to stop it.

sounds more like there's a problem in your code.

Can we control number of times paintComponent is called.
Can you tell me where is the problem in my code. ?
I am stuck in this problem.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Parth Pateld wrote:Can we control number of times paintComponent is called.

No. And you shouldn't even want to do that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Want to add Horizontal and vertical scroll bar in my code