File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I add my painted panel into ScrollPane?

 
Zobair Imran
Greenhorn
Posts: 18
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
 
Zobair Imran
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much indeed - Mr. m Korbel.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic