• 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

GUI Scrollbar and file browser

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to get some GUI's working. I am currently using a JFrame and displaying an image. If the image is too big for the screen though, some of it gets cut off. I want to add a scrollbar (vertical for right now) so I can scroll down and see the rest of the pic. This is what I have so far:


class Picture extends JPanel
{
JFrame frame;
static Image image;

public void display()
{
///////////////////CODE////////////////////////LEFT//////////OUT////////////
Picture display = new Picture();

frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(BorderLayout.CENTER, display);
frame.setSize(width,height);
frame.setVisible(true);
}



I am wondering if someone can explain how to use the scrollbar constructor(what all the int values do) and how to get it displayed on the side of the JFrame.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swing often winds up with many containers nested in each other. Look into putting a ScrollPane on the content pane, then another JPanel on top of that to hold your screen. YOu can set ScrollPane properties to have vertical and/or horizontal scroll bars all the time or only when needed.

Warning: I don't do a lot of Swing so that may not be exactly the order to lay things together. Snoop around the JavaDoc or google for "scrollpane example" and I bet you'll find your way!
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Eric,

You may find explanation and sample code for scrolling large picture at How to use scrollpane


Best regards,
 
reply
    Bookmark Topic Watch Topic
  • New Topic