How to add scroll bars to a panel

Hi
Can anyone plz tell me how to add a scroll bar to a panel created within a JFrame
Regards
ats

import javax.swing.*;
import java.awt.*;
class Testing extends JFrame
  public Testing()
    setLocation(300,200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel jp = new JPanel();
    jp.add(new JLabel("Label on a panel"));
    jp.setPreferredSize(new Dimension(200,300));
    JScrollPane sp = new JScrollPane(jp);
    sp.setPreferredSize(new Dimension(200,200));
    getContentPane().add(sp);
    pack();
  public static void main(String args[]){new Testing().setVisible(true);}
}

Similar Messages

  • How to add scroll bar in child form ( vb6.0 )

    look at this picture link (i think you will understand the issue)
    http://tinypic.com/r/25k232u/8
    These information(class1,class2 ……) are loaded from database and this time the information is too much and it moves down to the appearing part of the window and unable to view these items
    How to add scroll bar in visual basic child form so that the data items can be viewed by scroll in case it go beyond the screen.

    Hi,
    Welcome to MSDN.
    I am afraid that these forums donot support VB6 any more, you could refer to this thread:
    Where to post your VB 6 questions
    You could consider posting this issue in these forums below:
    These forums do not support Visual Basic 6, however there are many third-party support sites that do. If you have a VB6-related question please visit these popular forums:
    VB Forums
    VB City
    Thanks for your understanding.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to add scroll bar within af:showDetail

    I have added a af:panelGroupLayout to af:showDetail, and set the "layout" property of the panel group layout out to "scroll". However, the scroll bar still does not show up within af:showDetail. If I set the height for the panel group layout within af:showDetail, then the scroll bar shows. But then it will not stretch vertically upon stretching the dialog vertically. Is it possible to add scroll bar within af:showDetail?
    Here's a sample code which I tried -
    <*af:panelStretchLayout* id="psl1">
    <f:facet name="center">
    <*af:showDetail* disclosed="false" id="sd1" disclosedText="Metadata"
    undisclosedText="Metadata">
    <*af:panelGroupLayout* id="pgl2"
    inlineStyle="background-color:White;"
    layout="*scroll*">
    </panelGroupLayout>
    </af:showDetail>
    </f:facet>
    </af:panelStretchLayout>

    Yes, you can try panelStretchLayout as well.
    Copy following fragment into an empty <af:document> to see the difference.
    <af:form id="f1">
    <af:showDetail disclosed="true" id="sd1">
    <af:panelStretchLayout id="psl1">
    <f:facet name="bottom"/>
    <f:facet name="center">
    <af:panelGroupLayout id="pgl1" layout="scroll">
    <af:outputFormatted value="outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>"
    id="of1"/>
    </af:panelGroupLayout>
    </f:facet>
    <f:facet name="start"/>
    <f:facet name="end"/>
    <f:facet name="top"/>
    </af:panelStretchLayout>
    </af:showDetail>
    <af:showDetail disclosed="true" id="sd2">
    <af:panelGroupLayout id="pgl2" layout="scroll">
    <af:outputFormatted value="outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>outputFormat1&lt;p>"
    id="of2"/>
    </af:panelGroupLayout>
    </af:showDetail>
    </af:form>
    Enjoy ADF...
    Todd

  • How to add scroll bar to a labview wave graph?

    I want to know if there is a to add scroll bar to a labview wave graph.

    Look here:
    http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=5065000000080000001E400000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0

  • How to add scroll bar in webi table

    Hi Experts,
    Currently i am working on webi report it consist lot of tables and charts. As per my requirement the webi table should contain scroll bar instead of showing all data in single shot. And user will scroll down  if he/she required.  Is it possible in webi?
    Regards,
    PRK.

    Hi Praveen,
    Adding scroll ball in Webi table is not possible currently.
    Requests has been raised by some people in SAP Idea place, see the link below for more details.
    You can vote in SAP Idea place for getting this feature
    Add scroll bars for Webi tables : View Idea

  • 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.

  • Any Possible to add Scroll Bars to SysLink Control in MFC

    If there is any chance to add Scroll Bars to SysLink Control in VC++ MFC Application?

    Hi J Sathish Kumar,
    CLinkCtrl class derive form CWnd class, so it can create with the common windows style WS_VSCROLL. So we could create a syslink control with this style.
    https://msdn.microsoft.com/en-us/library/xw25kwch.aspx
    PTCHAR url =
    _T("Link 2) ")
    _T("<A HREF=\"http://msdn2.microsoft.com/en-us/visualc/default.aspx\">")
    _T("Microsoft VC++ Home")
    _T("</A>");
    //m_mylink is a object of a class derive from CLinkCtrl class.
    m_mylink.Create(url,
    (WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_BORDER|WS_VSCROLL),
    CRect(
    100, 100,
    400, 240),
    this,
    IDC_SYSLINK2);
    You need to create a class derive form CLinkCtrl class. And you will find the scrollbar cannnot scroll. Here is a workaround:
    LRESULT CMyLinkCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    // TODO: Add your specialized code here and/or call the base class
    if (message == WM_NCHITTEST || message == WM_NCLBUTTONDOWN || message == WM_NCLBUTTONDBLCLK)
    return ::DefWindowProc(m_hWnd, message, wParam, lParam);
    return CLinkCtrl::WindowProc(message, wParam, lParam);
    Set the scrollbar information.
    int CMyLinkCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
    if (CLinkCtrl::OnCreate(lpCreateStruct) == -1)
    return -1;
    // TODO: Add your specialized creation code here
    SCROLLINFO vinfo;
    vinfo.cbSize = sizeof(vinfo);
    vinfo.fMask = SIF_ALL;
    vinfo.nPage = 30
    vinfo.nMax = 140
    vinfo.nMin=0;
    vinfo.nTrackPos = 0;
    SetScrollInfo(SB_VERT, &vinfo);//
    return 0;
    Handle the WM_VSCROLL message event in your new class CMyLinkCtrl.
    void CMyLinkCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
    // TODO: Add your message handler code here and/or call default
    SCROLLINFO scrollinfo;
    GetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL);
    switch (nSBCode) {
    case SB_BOTTOM:
    ScrollWindow(0, (scrollinfo.nPos - scrollinfo.nMax) * 10); scrollinfo.nPos = scrollinfo.nMax;
    SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL); break;
    case SB_TOP: ScrollWindow(0, (scrollinfo.nPos - scrollinfo.nMin) * 10); scrollinfo.nPos = scrollinfo.nMin;
    SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL);
    break;
    case SB_LINEUP:
    scrollinfo.nPos -= 1;
    if (scrollinfo.nPos<scrollinfo.nMin) {
    scrollinfo.nPos = scrollinfo.nMin;
    break;
    SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL);
    ScrollWindow(0, 10);
    break;
    case SB_LINEDOWN:
    scrollinfo.nPos += 1;
    if (scrollinfo.nPos>scrollinfo.nMax) {
    scrollinfo.nPos = scrollinfo.nMax; break;
    SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL); ScrollWindow(0, -10);
    break;
    case SB_PAGEUP:
    scrollinfo.nPos -= 5;
    if (scrollinfo.nPos<scrollinfo.nMin) {
    scrollinfo.nPos = scrollinfo.nMin;
    break;
    SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL); ScrollWindow(0, 10 * 5);
    break;
    case SB_PAGEDOWN:
    scrollinfo.nPos += 5;
    if (scrollinfo.nPos>scrollinfo.nMax) {
    scrollinfo.nPos = scrollinfo.nMax;
    break;
    SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL); ScrollWindow(0, -10 * 5);
    break;
    case SB_ENDSCROLL:
    break;
    case SB_THUMBPOSITION:
    // ScrollWindow(0,(scrollinfo.nPos-nPos)*10); // scrollinfo.nPos = nPos;
    // SetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL);
    break;
    case SB_THUMBTRACK:
    ScrollWindow(0, (scrollinfo.nPos - nPos) * 10);
    scrollinfo.nPos = nPos;
    SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL);
    break;
    CLinkCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
    Above code is just for test and help you understand how to add the scrollbar, you could make it more suitable for your situation. Hope this helps some. Example Screenshot:
    Best regards,
    Shu
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Removing scroll bar from Nav Panel & Work Area layout

    Hi Guys,
    I have a requirement to remove the scroll bar which appears between nav panel and Work Area in 'Nav Panel and work area layout'.
    I would like it to be as a single page as we get in narrow: wide layout.
    Well I could just do it by using a narrow:wide layout, but the challenge is I also need the collapse/expand Icon which we get in Nav Panel/WA layout.
    I am looking fcor help with either
    1. Removing the scroll bar from Nav Panel/WA layout
    Or
    2. Adding collapse/expand  icon to narrow:wide layout.
    Thanks,
    Yomesh

    Hi Yomesh ,
    If you want to enable the expand/collapse icon , then you can set the property named Show Tray of the page to yes and then test . By default the property meant for showing the expand/collapse icon is set to yes . You only need to enable the tray and check .
    I did not get the requirement that you have with respect to scrollbar . Where is that scrollbar appearing that you want to remove?
    Regards
    Mayank

  • How to Hide Scroll Bars in Hierachy Tree?

    Hi!
    How to Hide Scroll Bars in Hierachy Tree?
    Thanks!

    when I populate the Tree Item with populate_tree(). I get a hierarchical tree. when the tree populates, two scroll bars (on it right and bottom) are displayed. Can I hide them?

  • How to add scroll function in  the applet launched by  Java Web Start?

    I have Java Web Start installed in order for the applet to launch.The applet size: width:700 height:1000
    my compuer resolution:800*600
    the applet launched by Java Web Start can only be seen partly,especially height.How to add scroll function in the applet launched by Java Web Start?
    Thanks for help.
    email:[email protected]

    You can very easily add a JScrollPane manually between the Applet and your content. Perhaps it would be beter if javaws did this automatically. In the browser, an applet can be any size. In Java Web Start an applet is directly contained within a JFrame, so it cannot be smaller than the minimum size of a JFrame, or Larger than the max.

  • How to handle scroll bar in table control in bdc

    hi friends,
       how to handle scroll bar coding in table control in bdc
    Thanks & Regards,
    Srinadh D

    hi,
    check the sites :
    table control scrolling:
    Scrolling in table control
    Re: scrolling in table control
    Table control - Vertical scrolling problem
    table control scrolling problem

  • How to add a button on a panel's title bar?

    Hi,
    How can I add a button to a panel's title bar? Buttons that
    are simply added to a panel's title bar become invisible.
    -Altu

    One way is to put your button component oustide your Panel
    tag in your MXML. The set the x/y coordinates for the button so it
    is on the Panel.
    <mx:Panel x="20" y="168" width="250" height="118"
    layout="absolute"/>
    <mx:Button x="73" y="173" label="Button"/>

  • Add scroll bars to TextArea - how?

    I have an application which reads user input to a text file and then on click of JButDisplay reads the contents of the file to a TextArea.
    Problem is I can't seem to get scroll bars onto the TextArea, I tried using JScrollPane,
    but had no luck (I'm using gridBagLayout)
    Could someone please advise me how to add scrollbars to this component?
    TADisplay2 = new JTextArea(10,20);     
                   c.ipadx = 12;
                   c.ipady = 12;
                        c.gridx = 2;
                        c.gridy=18;
                        c.gridwidth = 2;   //2 columns wide
                        c.gridheight = 4;
                             gridbag.setConstraints(TADisplay2, c);
                             contentPane.add(TADisplay2);

    1) Create scrollPanel
    2) Make it fill your content pane (or whatever area you wish to cover)
    3) Add your textArea to the scrollpanel

  • How to get rid of scroll bars in sub panels when displaying a VI which is part of a class?

    I am writing an application that applies different analyses to a set of data. The program must be flexible configurable. To not clutter the GUI with too much elements I ended up with the idea to load the needed user interfaces for each specific analysis dynamically into a single sub panel when needed. This works well without any problem.
    Due to the fact that all analyses share some common functionality I have decided to use LabVIEW classes for implementation. Each class has one VI representing the user interface to show in the sub panel.
    This works also well BUT the sub panel always shows a horizontal and vertical scroll bar I don't want to see!
    I have already learned that I need to change the user interface VI to a custom "Window Appearance" and disable the "Show scroll bar" properties. But this seems to work only for "normal" VIs but not for VIs that are part of a class.
    Any ideas?
    Ingo
    Solved!
    Go to Solution.

    Thanks Pixar, this was the right tip!
    Although: there seems to be a difference between "normal" VIs and VIs that are members of a class.
    For "normal" VIs it is sufficient to set the property to "Off While Running" and it works as expected.
    VIs part of a class need the "Always Off" setting" which is only accessible via right click on the scroll bars but not via the VI's properties box.
    Thanks and Regards
    Ingo

  • Adding a scroll bar to tabbed panel content?

    I have set a specific height to tabbed panels and I don't
    want them to expand according to content. Instead I want to add a
    scroll bar to the tabbed panels. How can i do this?

    Sure it's possible.
    Edit the TabbedPanelsContent class in the CSS file.
    Add a specific height to it and then add an overflow:auto;
    rule to it.
    .TabbedPanelsContent {
    padding: 4px;
    overflow: auto;
    height: 200px;
    When styling Spry Widgets, for the most part, just think of
    them as HTML. Add a height and a scrollbar just as you would to any
    DIV.
    Hope this helps,
    Don

Maybe you are looking for

  • New iPhone coming in Feb

    HI. While in LA last week I heard that Apple are bringing out a new iPhone in Feb with a much bigger memory. Does anyone know if this is true as I intend to get one for Christmas and would rather wait for the bigger memory so I can watch movies on it

  • Copy roto selection to same position in all frames

    I am using AE CS5 in Production Premium. I also have moca AE 3.1 that may be a better way of trying to isolate an object using planar tracking.  I need to replace an item that appears in the same position on all frames of a clip.  This is a previous

  • After sending attachment through mail using ABAP program.....

    Hello Experts, I am facing a problem to fulfill a requirement. My requirement is....sending the data of the internal table to an external mail with attachment(excel format). I have done with this. But when o am opening the excel sheet(attachment) it

  • Odd library behaviour.

    I'm stumped with a Library problem. I'm running Snowleopard 10.6.6 I'm running iTunes 10.1.1 I've got about 5000 tracks. My library is on an external firewire connected drive called MongoDisk. The disk was disconnected without ejecting it properly. (

  • How do I upload an XML file to salesforce using BULK API?

    Hi There, Please let me know how do we upload an XML file to salesforce using Bulk API? Thanks, ET