• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I add my painted panel into ScrollPane?

 
Greenhorn
Posts: 22
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://stackoverflow.com/search?q=[java]+[swing]+zoom
 
Zobair Imran
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much indeed - Mr. m Korbel.
 
reply
    Bookmark Topic Watch Topic
  • New Topic