Home java how to add jscrollpane to jpanel?

how to add jscrollpane to jpanel?




There are 20 buttons on the panel. How to add to this panel slider What could I choose a button?

UPD : added code from comment

for (int c = 0; c & lt; 20; C++) {
  ListButtons.add (new jbutton (integer.tostring (C)));
  ListButtons.get (C) .setPreferredSize (New Dimension (100, 100));
  panels [0] .add (ListButtons.get (C));
panels [0] .setborder (BorderFactory.CreateLineBorder (Color.Red));
Scrolller = New JScrollPane (Panels [0]);
scroller.setverticalscrollbarpolicy (Scrollplaconstants.vert iCal_ScrollBar_Alway S);
Scroller.Sethorizontalscrollbarpolicy (ScrollPaneConstants.ho rizontal_scrollbar_n Ever);
Add (BorderLayout.east, Scroller);

Answer 1

Example of Java Jpanel Inside JScrollPane? :

Public Class Scroller Extends JFrame {
  Public Scroller () Throws HeadlessException {
    Final Jpanel Panel = New Jpanel ();
    Panel.SetBorder (BorderFactory.CreateLineBorder (Color.RED));
    Panel.SetPreferredSize (New Dimension (800, 600));
    Final JScrollPane Scroll = New JScrollPane (Panel);
    Add (Scroll, BorderLayout.Center);
    setsize (300, 300);
    SetVisible (TRUE);
  Public Static Void Main (Final String [] Args) Thrown Exception {
    SwingUtilities.invokelater (new Runnable () {
      Public void Run () {
        new scroller (). SETVISIBLE (TRUE);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions