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 How can I add my painted panel into ScrollPane? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How can I add my painted panel into ScrollPane?" Watch "How can I add my painted panel into ScrollPane?" New topic
Author

How can I add my painted panel into ScrollPane?

Zobair Imran
Greenhorn

Joined: Jan 02, 2013
Posts: 10
I have created a Graph Panel where a graph paper is painted. I am actually writing codes for a Quadratic equation Graph. After the calculation, graph will be shown on clicking a certain button. my graph panel does not adjust in every screen as it is in a fixed mode that is it has no of certain rows and columns with certain heights and widths. it looks better when i see on my 17" monitor and it looks half when i see it on 15.6" laptop screen. Therefore, I'd like to add scrollPane. It does not work even I add it, whereas if I add any image it works. I have given my code for graphpanel below:



my graph panel example is :


Please it would be so kind if any one helps.
my second question is even if it is possible, shall I really be able to update this panel after every clicking the button of new calculation?

Thanks in Advance!
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 154
1. private JPanel createPanel() {

- JPanel has implemented FlowLayout, then there isn't changed LayoutManager for instance that returns JPanel, and (maybe) no reason to create duplicated JPanel (wiht BorderLayout)

- FlowLayout accepting only PreferredSize, child(s) is/are not resizable with contianer

- override getPreferredScrollableViewportSize instead of scrollPane.setPreferredSize(new Dimension(600, 60));

- override getPreferredSize instead of panel.setPreferredSize(new Dimension(500, 400));

2. public static void main(String args[]) {

- see Oracle tutorial Initial Thread

3. class GraphPanel extends JPanel {

- custom painting in Swing is done by override paintComponent instead of paint()

- override getPreferredSize, then getHeight/Weigth returns proper coordinates for Java2D inside JPanel
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37958
    
  22
Zobair Imran, please always use the code button; I am trying to use it on your post, and if it works it will look so much better Always use spaces for indenting, never tabs.
Zobair Imran
Greenhorn

Joined: Jan 02, 2013
Posts: 10
Dear Mr. Korbel, thanks for your reply. it would be nice if any little bit example is given because no fruitful information on ScrollPane I have right now.

Dear, Mr. Campbell, thanks for your advice. I do will obey what you have instructed me. Mistakes might be forgiven as I am new on this side.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 154
http://stackoverflow.com/search?q=[java]+[swing]+zoom
Zobair Imran
Greenhorn

Joined: Jan 02, 2013
Posts: 10
Thank you very much indeed - Mr. m Korbel.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I add my painted panel into ScrollPane?
 
Similar Threads
fluctuation
Graphs.
Ladders and slides
Speedway Trials
Applet - Graphing Quadratic Function Help