ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Java Swing:Scrollable JPanel

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java Swing:Scrollable JPanel

    Hi all, I am having a JPanel in which I am adding JLabel,JButton,JComboBox etc. I want to make this
    JPanel scrollable. I am using the code as follows. But although I am getting the scrollbar it is not active. Only that bar is coming on the right side of my JFrame(jf). Can anybody suggest me a way out?


    JPanel jp = new JPanel();
    jp.setLayout(null);
    JLabel label = new JLabel("Image");
    label.setFont(new Font("Serif", Font.BOLD, 15));
    label.setBounds(250,220,250,20);
    label.setForeground(Color.white);
    jp.add(label);


    JPanel panelToScroleOver = new JPanel();
    panelToScroleOver.setLayout(new BorderLayout());
    panelToScroleOver.add(jp);


    JScrollPane editorScroll = new JScrollPane(panelToScroleOver);
    editorScroll.setVerticalScrollBarPolicy(JScrollPan e.VERTICAL_SCROLLBAR_ALWAYS);
    editorScroll.setHorizontalScrollBarPolicy(JScrollP ane.HORIZONTAL_SCROLLBAR_NEVER);
    JTabbedPane documents = new JTabbedPane();
    documents.add("doc1", editorScroll);
    documents.setPreferredSize(new Dimension(50, 500));

    jf.getContentPane().setLayout(new BorderLayout());
    jf.getContentPane().add(editorScroll);

    jf.setPreferredSize(new Dimension(300, 300));
    jf.setVisible(true);

    If I add a JTextPane object to the panelToScroleOver panel then that textpane is scrolling. How to make my panel (jp ) to scroll?

    Thanks,
    Meera.

  • #2
    Re: Java Swing:Scrollable JPanel

    Sorry Meera, looks like ur the java expert here

    Jamie
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Java Swing:Scrollable JPanel

      It is ok Jamie,
      I found solution to my problem. It is actually very simple and not that much code is needed!! I will place here the solution . Just have a look at it.

      jp.setPreferredSize(new Dimension(1500,1500));

      JScrollPane editorScroll = new JScrollPane(jp);

      jf.getContentPane().add(editorScroll);

      jf.setPreferredSize(new Dimension(300, 300));
      jf.setVisible(true);

      Regards,
      Meera.

      Comment


      • #4
        Re: Java Swing:Scrollable JPanel

        Very cool.... where is Pondicherry???

        take care
        Jamie
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: Java Swing:Scrollable JPanel

          Hai ,
          Pondicherry is in India. It is a central government ruled place. I am only working here (in HCL Infosystems Ltd). Actually my native place is Kerala.

          Comment

          Working...
          X