Disable the scroll bar when the content is less than the viewport?

Hello

I have a vertical scroll bar has always shown (JScrollPane.VERTICAL_SCROLLBAR_ALWAYS).
but I want that it should be disabled when the content in the display is lower at the height of the viewport.

For example, browser Chrome in Windows: when you open Google, the content of the page is fairly low in height and scrolling in Chrome bar will be disabled. As soon as you have enough content on the page of the scrollbar will be active.

How can I achieve this?
Thank you

Hello

It isn't really a problem, I just know that it is a limitation of the SWING, (...)
Almost all app have this behavior; It is not very nice visually.

I don't have Chrome and haven't seen this problem until now, anywhere (but it is true, I'm way behind in terms of GUI mode).
The behavior that I'm used to (and which Swing designers apparently supposed to be standard too), which is a scroll bar disappears when the width of the view does not justify it ( SCROLLBAR_AS_NEEDED ). Using SCROLLBAR_ALWAYS implies that you want to the scroll bar, no matter if the width of the merit. How the scroll bar looks like in this case sounds like a look and feel selection instead (I don't have older OSs, but maybe you know an operating system where this behavior is the norm? In this case, Yes, this is a limitation of the corresponding Swing L & F).

Maybe there is a work around.

Because this isn't the OS Lebanese armed forces, which can be "manually coded", by listeneing to resize events and thus change the appearance of the ScrollBar.
Assuming that the "disabled" appearance scroll bar is what you are looking for (no idea, it's just an example, if that do not meet your needs, you can do something else in the placeholder code), here is one, certainly dense enough, workaround.
Notice how the vertical and horizontal scroll bar is different (I applied workaround only to the latter).

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class TestDisableScrollBar extends JPanel
{
    private static final String SHORT_TEXT = "text";
    private static final String LONG_TEXT = "texttexttexttexttexttexttexttexttexttexttextte";

    private static void createAndShowGUI()
  {
        JFrame frame = new JFrame("Demo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JTextArea textarea = new JTextArea(5, 5); // just to take up some space.
        final JLabel label = new JLabel(SHORT_TEXT);
        JPanel view = new JPanel();
        view.setLayout(new GridLayout(2, 1));
        view.add(label);
        view.add(textarea);
        final JScrollPane widget = new JScrollPane(view, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        widget.getHorizontalScrollBar().setEnabled(false);
        widget.getViewport().addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                widget.getHorizontalScrollBar().setEnabled(
                        widget.getViewport().getWidth()<
                        widget.getViewport().getView().getWidth());
            }
        });
        frame.getContentPane().add(widget, BorderLayout.CENTER);
        JButton alternateText = new JButton("Switch width");
        alternateText.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                label.setText(label.getText().equals(SHORT_TEXT)?
                    LONG_TEXT : SHORT_TEXT);
            }
        });
        frame.getContentPane().add(alternateText, BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);
      }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
              }
          });
    }

  }

Tags: Java

Similar Questions

  • When I resize my window (smaller size mobile) my vertical scroll bar disappears if I'm less than 800px wide.

    It was in version 9.0.1 and now 10. I resize my window to test how my site looks like smaller screens (iTouch, iPad, etc.). Any suggestions? I don't have this problem in version 4.0.1 I serve up to this point.

    Which can happen if there are items on a toolbar taking a specific space.

    You can try to hide the toolbars when testing to see if that helps (view > toolbars or Firefox > Options).

    Start Firefox in Firefox to solve the issues in Safe Mode to check if one of the extensions or if hardware acceleration is the cause of the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > appearance/themes).

  • Without scroll bars when search results are displayed in the "content" section

    Hello

    I use reactive HTML5 in 2015 of Robohelp.

    The Azure_Blue layout works very well, but when search results are set to appear in the 'content' section no scroll bar is displayed, if you can't navigate to the results of research which are off the screen. Scroll bars are displayed when its set to appear in the sidebar. Tried with many different browsers - same result.

    Is it bug? Others do for this problem?

    See screen capture below.

    See you soon

    The CSS fix mentioned by Willam resolves the problem.

  • Disable the scroll bar when no overflow in the dynamic text field

    I use the UIScrollBar on a dynamic text field. I would like to make the scroll bar is not visible or turn it off if there are no more rows to display when initially displayed. Are there variables in a pile of data L0 I can check to see if the scroll bar can be disabled; 'lines of total in the text field' and 'lines per page' either, something that accomplishes the same thing?

    You can use the textfields maxscroll property to determine if a textfield can display all its text without scrolling.

  • Add vertical scroll bars to a content panel

    I need to use long passages of text in a fixed size content area, so I need to add a vertical scroll bar on the side. Muse support says that I have to use HTML code to do this. I'm a designer, not a coder, can someone walk me through it?

    Hi Jeff,

    I replied to your previous post, please refer to this topic:- https://forums.adobe.com/thread/1627033

    Kind regards

    Rohit Nair

  • all the tools in the upper part are disabled. side scroll bar does not work

    In my firefox, none of my utility tools in the upper side work. they are in a disabled state

    In addition, I am not able to scroll the sidebar automatically through the mouse.

    I raise the bar and down to put the page vertically

    This problem can be caused by that extended the Yahoo! toolbar or extension of Babylon also well down and covers the top of the browser window and therefore links and buttons in this part of the screen not clickable.

    Start Firefox in Firefox to solve the issues in Safe Mode to check if one of the extensions or if hardware acceleration is the cause of the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > appearance/themes).

  • Problem in the scroll bars when the screen is not any field focus...

    Hi all

    I have a screen on which I need to display a list of items. and the list total appears at the bottom of the list. everything works fine if the lily a few number of lines. but as soon as the number of rows and Lily exceeds the length of the screen, there is the problem. I don't see the total at the bottom because I can't scroll the list. Here is the code in my class. in the class list, I use a CustomGridManager, which shows data in a table (I downloaded it). I made a few changes in the present. the code for this handler is also attached. Please tell me what changes should I make, so that the screen can be the object of a scroll. (Please go through the code)...

    SerializableAttribute public class MyClass extends {screen

    public MyClass (dataList DataList []) {}

    Super(Manager.VERTICAL_SCROLLBAR |) Manager.VERTICAL_SCROLL);

    Super();

    int noOfColumns = 2;

    int noOfRows = dataList.length;

    int [] columnWidth = {50.50};

    CustomGridManager gfmHeader = new CustomGridManager (noOfColumns, 0, columnWidth);

    Adding headers

    LabelField lblHdrCol1 = new LabelField ("Col1");

    gfmHeader.add (lblHdrCol1);

    LabelField lblHdrCol2 = new LabelField ("Col2");

    gfmHeader.add (lblHdrCol2);

    VerticalFieldManager vfmTitle = new VerticalFieldManager();

    vfmTitle.add (new LabelField ("my class"));

    vfmTitle.add (gfmHeader);

    setTitle (vfmTitle);

    Addition of body

    GFM CustomGridManager = new CustomGridManager (noOfColumns, 0, columnWidth);

    for (int i = 0; i)< noofrows;="">

    LabelField lblICol1 = new LabelField (dataList [i] .getCol1 ());

    GFM. Add (lblICol1);

    LabelField lblICol2 = new LabelField (dataList [i] .getCol2 ());

    GFM. Add (lblICol2);

    Adding a footer

    CustomGridManager gfmFooter = new CustomGridManager (noOfColumns, 0, columnWidth);

    LabelField lblFtrTotal = new LabelField ("Total");

    gfmFooter.add (lblFtrTotal);

    LabelField lblFtrValue = new LabelField ("CalculatedValue");

    gfmFooter.add (lblFtrValue);

    Add (gfmHeader);

    Add (new SeparatorField());

    Add (GFM);

    Add (new SeparatorField());

    Add (gfmFooter);

    Add (new SeparatorField());

    }

    ======================================================

    SerializableAttribute public class CustomGridManager extends Manager {}

    private int [] columnWidths;

    private int [] staticColumnWidth;

    private int columns;

    private int allRowHeight = - 1;

    /**

    * Built a new CustomGridManager with the number of columns specified.

    * Lines will be added to the need to display the fields.

    * Fields will be added to the grid in the order they are added to this Manager.

    to complete each row from left to right:

    *

    * For example, a Manager 2 column:

    *

    * [Field1] [Field2]

    * [Field3] [Field4]

    * [Sphere5]

    *

    * Column widths are equal, and the Manager will attempt to use the entire available width.

    Each line height will be equal to the height of the field higher in the same row.

    * Styles positional field are met, then the fields that are smaller than the row/column

    * they can be set to left, right, up down, or centered. They have by default at the top left.

    *

    @param columns number of columns in the grid

    @param style

    */

    public GridFieldManager (columns int, long style) {}

    Super(Manager.VERTICAL_SCROLLBAR |) Manager.VERTICAL_SCROLL);

    Super (style);

    This.colonnes = columns;

    }

    /**

    *

    @param columns columns number of columns in the grid

    @param style

    @param columnWidths width of each column in a table

    */

    public GridFieldManager (columns int, long style, int [] columnWidths) {}

    Super(Manager.VERTICAL_SCROLLBAR |) Manager.VERTICAL_SCROLL);

    Super (style);

    This.colonnes = columns;

    this.staticColumnWidth = columnWidths;

    }

    protected boolean navigationMovement (int dx, int dy, int, int time status) {}

    int focusIndex = getFieldWithFocusIndex();

    While (dy > 0) {}

    focusIndex += columns;

    {If (focusIndex > = {getFieldCount())}

    Returns false; The focus moves on this manager

    }

    else {}

    Field f = getField (focusIndex);

    If (f.isFocusable ()) {/ / only move the focus on the fields of the object of focus}

    f.setFocus ();

    -DY;

    }

    }

    }

    While (dy< 0)="">

    focusIndex = columns;

    If (focusIndex< 0)="">

    Returns false;

    }

    else {}

    Field f = getField (focusIndex);

    If (f.isFocusable ()) {}

    f.setFocus ();

    DY ++;

    }

    }

    }

    While (dx > 0) {}

    focusIndex ++;

    {If (focusIndex > = {getFieldCount())}

    Returns false;

    }

    else {}

    Field f = getField (focusIndex);

    If (f.isFocusable ()) {}

    f.setFocus ();

    -DX;

    }

    }

    }

    While (dx< 0)="">

    -focusIndex;

    If (focusIndex< 0)="">

    Returns false;

    }

    else {}

    Field f = getField (focusIndex);

    If (f.isFocusable ()) {}

    f.setFocus ();

    DX ++;

    }

    }

    }

    Returns true;

    }

    protected void sublayout (int width, int height) {}

    int y = 0;

    columnWidths = new int [columns];

    If (staticColumnWidth == null: staticColumnWidth.length)<= 0)="">

    for (int i = 0; i)< columns;="" i++)="">

    columnWidths [i] = width/columns;

    }

    } else {}

    for (int i = 0; i)< columns;="" i++)="">

    columnWidths [i] = (width * staticColumnWidth [i]) / 100;

    }

    }

    On the field [] fields = Field [new columnWidths.length];

    currentColumn int = 0;

    rowHeight = 0 int;

    for (int i = 0; i)< getfieldcount();="" i++)="">

    fields [currentColumn] = getField (i);

    layoutChild (fields [currentColumn], columnWidths [currentColumn], height-y);

    If (fields [currentColumn] .getHeight () > rowHeight) {}

    rowHeight = fields [currentColumn] .getHeight ();

    }

    currentColumn ++;

    {If (currentColumn == columnWidths.length | I == {getFieldCount () - 1)}

    int x = 0;

    If (this.allRowHeight > = 0) {}

    rowHeight = this.allRowHeight;

    }

    for (int c = 0; c)< currentcolumn;="" c++)="">

    long fieldStyle is fields [c] .getStyle ();.

    int fieldXOffset = 0;

    long fieldHalign = fieldStyle & Field.FIELD_HALIGN_MASK;

    If (fieldHalign == Field.FIELD_RIGHT) {}

    fieldXOffset = columnWidths [c] - fields [c] .getWidth ();

    }

    Else if (fieldHalign == Field.FIELD_HCENTER) {}

    fieldXOffset = (columnWidths [c] - fields [c] .getWidth ()) / 2;

    }

    int fieldYOffset = 0;

    long fieldValign = fieldStyle & Field.FIELD_VALIGN_MASK;

    If (fieldValign == Field.FIELD_BOTTOM) {}

    fieldYOffset = rowHeight - fields [c] .getHeight ();

    }

    Else if (fieldValign == Field.FIELD_VCENTER) {}

    fieldYOffset = (rowHeight-fields [c] .getHeight ()) / 2;

    }

    setPositionChild (fields [c], x + fieldXOffset, y + fieldYOffset);

    x += columnWidths [c];

    }

    currentColumn = 0;

    y += rowHeight.

    }

    If (y > = height) {}

    break;

    }

    }

    totalWidth int = 0;

    for (int i = 0; i)< columnwidths.length;="" i++)="">

    totalWidth += columnWidths [i];

    }

    setExtent (totalWidth, Math.min (y, height));

    }

    }

    Do you really want now fields is active.

    You can try adding a NullField after your Manager - a NullField is active, if it does not size.

    Other than that, you can try the substitution of navigationMovement and Manager.setVerticalScroll to go up and down the window scrolling.  I think it should work, although I never did.  You can control the scope of the first Manager to ensure that you do not have to scroll through to the end.

  • Horizontal scroll bar is missing in the region without borders

    Hello

    I use v4.2.1.00.08 APEX and used 24 theme.

    I'm not able to see the horizontal in the region without borders scroll bar when necessary. I just used the code inside the < style > tag to display the scroll bar, below

    #RPT .uRegionContent
    {
    overflow:auto;
    }
    
    

    It works, but now I can see the only horizontal scroll bar for this region not in the browser. Can someone help me get the horizontal scroll bar in the browser.

    horizontal.JPG

    I created a test case for this species,

    https://Apex.Oracle.com/pls/Apex/f?p=32974:3:8262817666057:no

    WS/Nations United/PWD: adhimaha/adhimaha/adhimaha

    Can someone help me on this...

    Thanks in advance,

    Adhi

    Lakshmi,

    Check in your page 9 of the application or the tab Test Pars control.

    hope this has solved your problem.

    changes made

    1. create the new model of the region as a region without borders copy model

    2. change the region class 'uIRRegion' instead of 'uRegion '.

    3. apply this classic report template.

    Leave.

  • Help to remove the double scroll bar!

    Having a problem when I export this site on BusinessCatalyst. At first I thought it was only with IE and Mozilla, but it seems that Chrome is also not me...

    I have a double vertical scroll bar when I load the site, it is an example for a future customer, but I can't seem to get rid of the double scroll bar.

    I think that the problem should be with the file global css but still cant fix it! Help

    * edit *.

    http://bgchawthrone.BusinessCatalyst.com/index.html

    Post edited by: Lightbonds * I forgot to add the link

    Thank you for posting.

    You are right, its in the global css file. Please refer to this screenshot: https://screencasteu.worldsecuresystems.com/aish/2013-04-24_2225.png

    I unchecked overflow-y: scroll; and the additional scroll bar was missing, as you can see in the screenshot above.

    If you are comfortable with CSS, you can log into the Admin Panel and fix it from here: https://screencasteu.worldsecuresystems.com/aish/2013-04-24_2230.png

    I hope this helps.

    Kind regards

    Scott Raj Rouanet

  • The vertical scroll bar of a Tilelist style

    Is it possible in flex for the vertical scroll bar of a tilelist style, rather than using the boring default scroll bars? What I have in mind is to have a place and a down arrow in the top and bottom where the regular scroll bar would actually then when my tilelist has more items than do the heaight these arrows will and act as a scroll bar.

    Is this possible?

    This example uses Degrafa (right click to view Source):

    http://PV3D.org/2009/04/14/theres-more-than-one-way-to-skin-a-ScrollBar/

    http://www.FoxArc.com/blog/article/101.htm

    If this post answers your question or assistance, please mark it as such.

  • OT: Firefox 43.0.3 - Page scroll bars have disappeared?

    WTF happened for automatic vertical page scroll bars when the content was deeper than the browser window? They seem to have disappeared and may be referred to only by pulling on the window wider or narrower. My mouse wheel does not work at the moment so have automatic vertical scrollbars in a browser is a must if it happen - it just seems to be simple stupid idea.

    Operating system

    Humm that's just weird - scrollbars yesterday, no today - after further investigation its an option under "system preferences" on Mac. Since I have not touch the "system preferences", I do not know why the scroll bars should disappear all of a sudden. After selecting the appropriate setting now, they are now back - is just like when the machine suddenly decide just to do his own thing.

  • Scroll bar disappears on publish

    In the latest version of edge animate (October 2014), I see the scroll bars when I apply 'Auto' to a symbol, but when I publish, the scroll bars disappear.

    Any advice?

    Thank you!

    I discovered the solution / workaround. If this happened to you, after you have created your symbol with scrolling of content, go to the left hand from the bottom of the dashboard interface box animate and make sure "Clip" is on - the numbers should appear in green - not grayed out.

    Now when you test in Safari, your scroll bars will appear. Yay!

  • Linux Firefox 38 Scroll Bars change (for worse) behavior

    With the update for Firefox 38, the scroll bars are are suddenly bad. The correct behavior for Linux scroll bars when you click on above view indicator (the part that you can move) is to move to the top of the screen and when you click below view indicator is to move to the bottom of the screen. When you the Middle click in an invisible box, it moves you directly to this part. And you can enter the indicator and drag it anywhere.

    With 38, when you click above or below the indicator view, it now moves you directly to this part/area rather than move to the top or the bottom of the SCREEN. This is not another Linux applications - LibreOffice, claws, Pluma, Thunar, etc.. It is inconsistent and a mess of support. Worse, I searched on the preferences and about: config and I cannot find a way to put it back the way that it is supposed to work (as it did in Firefox 1 to 37 and even Netscape Navigator). What is going on?

    Help! Thank you

    HI crxssi,
    I understand that in the linux version of Firefox, there is a difference in the way that scrolling works in version 37 and 38.

    There are two places that control smooth scrolling:
    Subject: #advanced under 'Général' preferences there are scroll smoothly.

    There was another topic: config entry mentioned here: https://support.mozilla.org/en-US/que.../981140

    However if there was a change in the update, please post if there is not always an improvement.

  • How can I decrease the margin in a smart form of polygon/circle less than '0 '.

    Hello. I'm trying to text in a hexagon shape smart, and I don't want to get carried away, but just stay on the same line (it isn't long text). The margin is set to '0', but which corresponds to the upper-left corner of the form, not the point middle left.  Is there a way to change this?  If this isn't the case, would you suggest combining two intelligent forms?  A rectangle (w / text) inside the hexagon?  Thanks for your help.

    Billmargins.jpg

    Just for future reference.  I finished my Hexagon to drawing.  I found an image of the form online - who broke in the background of a slide and showed the gridlines. Then, I magnified the size very important and plotted with a polygon line (one of the smart shape options).  You can actually move the scroll bar when you draw that allows, if you have magnified the screen and can not see the whole shape at once.

    I saved it as a form customized under 'style' in 'Properties' on the right screen.  When I add a text now, it fills the whole shape of smart:

  • Unwanted Hor. scroll bars in IE

    Hi all

    I designed a web page in Dreamweaver MX using frames (3-T, L, C) when I have view it in Firefox scroll bars appear on the right side, which is OK, but when I see her in IE scroll bars are displayed on the right AND the low, even thow there is nothing to scroll to the left or right too.

    I tried scrolling = 'no', the resizing of images, etc. My video size is 1024 x 768, but the HTML file is only 800 wide, that should fit without issue in 1024.

    In addition, I get only the hor scroll bar when there is a right scroll bar. In other words, if I have on a page like the page, a right scroll bar appears with a low. Very weird!

    Any ideas how to get rid of the bottom scroll bar in IE?

    Very much appreciated.

    >... into account all widths, the elements of the page.

    But that wouldn't produce the bar horizontal scroll in Firefox, too? Not
    just Internet Explorer?

Maybe you are looking for