Double Scroll Bars, Side By Side, End To End, In A JScrollPane

I'm trying to create double scroll bars next to each other, end to end. One scroll bar is for the position in the grid, while the other, smaller scroll bar controls the zoom level. I am masquerading a JPanel as a JScrollBar. I'm adding two scroll bars to the panel, and encapsulating the panel in a subclass of JScrollBar. You might wonder why I would do that. Because JScrollPane only accepts JScrollBar classes in setHorizontalScrollBar() and setVerticalScrollBar(). I tried to override every painting method I could think of that was important, but when I test it, nothing is shown. It is completely blank. Here is the code below. I know I still have to override the general JScrollBar methods and pass them to the primary scrollbar. Does anyone have any ideas on how to do somethink like I am attempting to do?
import java.awt.*;
import javax.swing.*;
import java.lang.reflect.*;
* <p>Title: </p>
* <p>Description: This class masquerades as a JScrollBar, but it wraps two scrollbars next to each other. The
* main scrollbar, and the secondary scrollbar which is smaller. Any calls which treat this as a regular scrollbar
* will return the main scrollbar's values, while the special methods can be used to return the seondary scrollbar's
* values.
* </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
public class DoubleScrollBar extends JScrollBar {
  JPanel panel = new JPanel();
  JScrollBar primary;
  JScrollBar secondary;
  public DoubleScrollBar(int orientation) {
    init(orientation);
  void init() {
    panel.setLayout(new GridBagLayout());
    if ( orientation == JScrollBar.HORIZONTAL ) {
      primary = new JScrollBar(JScrollBar.HORIZONTAL);
      secondary = new JScrollBar(JScrollBar.HORIZONTAL);
      GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.75, 0.0,
          GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
      panel.add(primary, gbc);
      gbc.gridx = 1;
      gbc.weightx = 0.25;
      gbc.anchor = GridBagConstraints.EAST;
      panel.add(secondary, gbc);
    } else if ( orientation == JScrollBar.VERTICAL ) {
      primary = new JScrollBar(JScrollBar.VERTICAL);
      secondary = new JScrollBar(JScrollBar.VERTICAL);
      GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.75,
          GridBagConstraints.NORTH, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0);
      panel.add(primary, gbc);
      gbc.gridy = 1;
      gbc.weighty = 0.25;
      gbc.anchor = GridBagConstraints.SOUTH;
      panel.add(secondary, gbc);
  public Dimension getPreferredSize() {
    return panel.getPreferredSize();
  public void setPreferredSize(Dimension d) {
    panel.setPreferredSize(d);
  public Dimension getSize() {
    return panel.getSize();
  public void paint(Graphics g) {
    panel.paint(g);
  public void paintAll(Graphics g) {
    panel.paintAll(g);
  protected void paintComponent(Graphics g) {
    try {
      Method m = panel.getClass().getMethod("paintComponent", new Class[] {Graphics.class});
      m.invoke(panel, new Object[] {g});
    catch (SecurityException ex) {
      System.out.println("SecurityException");
    catch (NoSuchMethodException ex) {
      System.out.println("NoSuchMethodException");
    catch (InvocationTargetException ex1) {
      System.out.println("InvocationTargetException");
    catch (IllegalArgumentException ex1) {
      System.out.println("IllegalArgumentException");
    catch (IllegalAccessException ex1) {
      System.out.println("IllegalAccessException");
  public void paintComponents(Graphics g) {
    panel.paintComponents(g);
  public void repaint(long tm, int x, int y, int w, int h) {
    if ( panel != null ) {
      panel.repaint(tm, x, y, w, h);
  public int getWidth() {
    return panel.getWidth();
  public int getHeight() {
    return panel.getHeight();
  public static void main(String[] args) {
    JFrame f = new JFrame();
    DoubleScrollBar dsb = new DoubleScrollBar(JScrollBar.HORIZONTAL);
    dsb.setPreferredSize(new Dimension(200, 50));
    f.getContentPane().add(dsb);
    f.pack();
    f.show();

I know this isn't zooming, but maybe it will help.import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test3 extends JFrame {
  MyPanel mp = new MyPanel();
  public Test3() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    JScrollBar jsb = new JScrollBar();
    jsb.addAdjustmentListener(new AdjustmentListener() {
      public void adjustmentValueChanged(AdjustmentEvent ae) {
        mp.setSize(ae.getValue()*5);
    content.add(jsb, BorderLayout.EAST);
    mp.setPreferredSize(new Dimension(500,500));
    content.add(new JScrollPane(mp), BorderLayout.CENTER);
    setSize(300, 300);
  public static void main(String[] args) { new Test3().setVisible(true); }
class MyPanel extends JPanel {
  int size;
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setColor(Color.red);
    g.drawRect(10,10,size,size);
  public void setSize(int size) {
    this.size=size;
    repaint();
}

Similar Messages

  • What can i replace an iframe with? (Death to double scroll bars!!)

    So the site I'm working with has a ton of links all directed to an iframe.  The iframe is set to a fixed size and will not expand/contract with the linked content so i end up with two scroll bars.
    Here is the web site.
    I was hoping for a 'quick' fix to replace the iframe with some kind of object that the links could dump their pages to that would expand the length of the site as needed.
    Any help would be much appriciated!!
    Thanks!

    Use Server-side includes for common headers, menus and footers.  Or build a DW Template file (dwt) and use it to spawn new site pages.
    Guidance  on when to use DW Templates, Library Items and SSIs  -
    http://www.adobe.com/devnet/dreamweaver/articles/ssi_lbi_template.html
    More on DWTemplates -
    http://forums.adobe.com/message/2032104#2032104
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb
    www.alt-web.blogspot.com

  • How do I get rid of double scroll bars when integrating a tumblr blog on my muse website?

    Hi there,
    Iim having problems getting rid of the double scrollbar I get when integrating a tumblr blog to my muse website? Is there a way to integrate the blog so I just get 1 scroll bar- just like on all other pages?
    Thank you

    Im not quite sure I seem to get it right. How do you suggest I change this iframe that I have imbedded?
    <iframe width="100%" height=1500px" src="http://xxxxxxxxxxxxxxxxx.tumblr.com" frameborder="0"  overflow:hidden;"></iframe>
    Thank you!

  • No double-scroll bar arrows in iTunes 7

    I like a lot about 7, (gapless playback, hooray!) however I'm disappointed that the trick to add arrows to both ends of the scroll bar ( there are many pages that describe this, here's one ) does not affect iTunes 7. There are only one set of arrows.
    Others seem to confirm this, but I've not found a workaround/remedy.
    Anyone know if there another way to do this?

    I can't believe that after 7 versions, support for keyboard access in dialog boxes still hasn't been enabled. No sheets, either. iTunes has always felt like a glorified port of a Classic app.

  • Please Help me place the arrows of my ScrollPane scroll bar together on one end of the scroll track!!

    I have a scrollpane component with a movie clip of some
    thumbnail images.
    I just want to have its scrollbar arrows together on one end
    of the track (or together ANYwhere) instead of having them at
    opposite ends of the scroll track.
    I have been able to customize the appearance of the
    scrollpane and its scrollbar using the HaloTheme library, but that
    approach has so far been of no use in getting the arrows together.
    I cannot tell you how deeply any help will be appreciated. I
    will probably sob and mewl with gratitude, the way I imagine
    someone lost in a vast rain forest for many weeks mewls when
    rescued. I am desperate. I am going insane. Please, please help me.

    Cherrylanenc are you on a managed network?  If not then I would recommend reviewing the steps listed in Sign in, activation, or connection errors | CC, CS6, CS5.5 - http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html.

  • Removing double scroll bars in Alerts in 11g

    When opening Alerts in 11g, it looks like the alert is a panel inside the browser instead of opening up a new browser window. For reports that are large, there is a scrollbar within a scrollbar.
    How can the size of the alert box be increased so that only one scrollbar shows?

    I am just wondering whether you were able to fix this issue? If so, can you please share with me.
    thanks
    Mahesh

  • Scroll bar does not scroll far enough to view last page in thumbnail images

    When using Adobe Acrobat, and have the thumbnails/pages panel open on the left side, the scroll bar will not scroll far enough down to show the last row of thumbnails. For example, have a 40-page document open with the Pages Panel open showing page thumbnails in rows of 3. When the scroll bar reaches the bottom, the last row shows pages 37, 38, and 39. Where is page 40? If you look closely, you can see a sliver of the top of the thumbnail below page 37. There is no way to view the thumbnail because it is at the bottom of the list, and your scroll bar has reached its end.
    Is it confirmed that this is a bug in Adobe? If yes, is there any hotfix available for it?
    Your help will be greatful.
    Thanks

    How can I report this bug to Adobe? Is there any link where I can post this bug to Adobe or  email or contact details?
    Thanks

  • How to add scroll bar to JDesktopPane?

    Hi All,
         After download the "InternalFrameDemo.java" from the swing tutorial, I want to add scrollbars to JDesktopPane so that whenever a internal frame moves off the desktop view port, a scrollbar will display. I have tried many ways to implement this but no success.
    Do you know how to add scrollbars to JDesktopPane?
    Thanks
    Anson

    You can't get there from here! Assuming that wou want is to make the desktop scrollable that is.
    The trick to make somthing scrollable is to make JScrollPane CONTAIN the component to be scrolled. If you could ask the desktop to return the component it contains, you might have a chance but no luck, the desktop pane actually inherits a layered pane which is most likey is what you would like JScrollPane to contain.
    Now here's another angle to this story... the desktop is complex enough without scrollbars, why would you want to complicate things by adding a scroll bar anyway? Say one of its window is maximized and has a scrollbar of its own AND the desktop has one.... that makes TWO scroll bars side by side. Talk about confusing.
    I believe the desktop was designed so scroll bars can't be added for a very good reason: good UI practises.

  • SCROLL BAR OF WINDOW DOES NOT APPEAR IN THE WEB

    Hi OTN Memebers,
    My problem is in one of my form the canvas type is content. It's
    size is bigger than that of windows size. When i run the form in
    the client/server enviroment, the window scroolbars are
    displayed. But when i try to deploy the from on the web , the
    window scroll bars are not displayed.
    Any solution for this. Please help me out.
    Feroz.
    null

    Feroz A. Khan (guest) wrote:
    : Hi OTN Memebers,
    : My problem is in one of my form the canvas type is content.
    It's
    : size is bigger than that of windows size. When i run the form
    in
    : the client/server enviroment, the window scroolbars are
    : displayed. But when i try to deploy the from on the web , the
    : window scroll bars are not displayed.
    : Any solution for this. Please help me out.
    : Feroz.
    This is a VERY OLD known problem with the product. The solution
    is to put your content canvas on a stacked canvas and give the
    stacked canvas scroll bars. Then disable the windows scroll
    bars, otherwise you'll end up with 2 sets in Client/Server
    mode...
    Mark
    null

  • Drag JTabbedPane out of the main Frame and set scroll bars for the tabs

    hi ,
    Iam working on a Swing application . In it i have Six Tabs added to a single JTabbedPane. all the tabs are different class files . is it possible to drag any of the tabs out of the frame.
    how to add scroll bars for the tabs individually. i have tried adding JScrollPane to the main frame and add the JTabbedPane to the Scrollpane . the scroll bar was not visible and i have tried adding
    all the six tabs to the individual JScrollPanes and add the six scrollpanes to the TabbedPane .
    only the scroll arrows are visible , when i minimised or resized the application the scrollbars were not appearing .
    could any one help me to solve the above two problems.

    just trying.....
    public void mouseDragged(MouseMotionEvent e){
    // this event should be activated only when the Drag goes out of scope of the parent JFrame which i dont know how
    Component c=JTab.getComponentAt(JTab.getSelectedIndex());
    JFrameobj.getContentPane().add(c,"Center");
    }

  • Can i put the scroll bar on the left hand side of the page

    i am left handed and using a touchscreen asus and would like to get the scroll bar on the left

    Hi!
    Yes, you can!
    # Type "about:config" (without quotations) in the urlbar and hit Enter
    # Search for "layout.scrollbar.side" (without quotations) variable
    # Double click on that
    # Modify the value to "3" (without quotations)
    # Click Ok
    # Restart Firefox

  • On the right side of the br5owser there is a scroll bar, that scroll bar does not have any contrast and is almost invisible, can't find it ???

    Have seen some other questions similar to mine and they may be about same issue , but they say that the scroll bar vanishes, in effect it is still there but nearly invisible. Trying to click on it without knowing the exact location however causes the page to scroll uncontrolled. The other questions advised people to reset their browser to default but that didn't help at all. Have had this same issue for about the last 6 versions of firefox, all say in the 30s versions. Tried adding high contrast in Windows as an experiment but that didn't help at all either. Been trying help for some time and just now decided to ask my own question as other questioners may have given up or answerers may think it is resolved.
    In searching through help files it has led me to find a space based theme for the browser that I enjoy, but does not solve issue of course, so... all is not lost. Took a jpg of the image of the browser that shows the issue and am trying to upload it but looks like it is stuck in upload mode. Ugh "high speed" , anyhow maybe it uploaded and is not showing, the bar on the right is about 3/4 of the way down the side if you can see it, almost invisible.

    Did you try Firefox Safe Mode?

  • How can I get a scroll bar at the bottom of the page so I can see the right side of the page when I am using two windows?

    With two or three pages open, I have scroll bars that allow me to see the right side of the other pages, but not on the Firefox page.

    Thank you for the reply, Fred, but when I went to my saved screenshot, I realized that the shortcut on my desktop had opened in IE, not Firefox. There is no scroll bar and the directional arrows do not work. My daughter has been playing with my laptop again. When I set up the same conditions with Firefox, there is no scroll bar, but the arrows function properly, so I can read to the right edge of the page. Now to find someone who knows IE11. Thanks again, for your reply.

  • I have osx 10.6.8 and have lost the side scroll bars on Safari.  When I go into System Preferences there is NOT an "always" option for displaying Scroll Bar.  How do I get it them to display again?

    When using Safari the scroll bars no longer appear on the right hand side.  When I go into System Preferences the option to Always have the scroll bars displayed is NOT there.  How/Where do I go to get these to show all the time?

    It SHOULD be under the General tab in System Preferences:
    (Note that this is a Mavericks screenshot, but it should be there in Snow Leopard, too, if indeed you're still running 10.6.8 as your profile says)
    Clinton

  • I have a new mac pro and can't get a side scroll bar.  What can I do to get this?

    I have a new mac pro and can't get a side scroll bar.  How can I get this?

    The scroll bar is now set to appear automatically when you start scrolling with a trackpad or scroll wheel mouse. If you are using an mouse without a scrolling device, you should change a setting.
    In System Preferences, click General, and in the Show Scroll Bars section, click the option for how you want it to work. If you want to see them all the time click "Always."

Maybe you are looking for