Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

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,
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic