简体   繁体   中英

Scrollpane scrollbars to entire Jframe when resizing/adding components

I edited my project using only swing components and a layout (not null).So now i want to add scrollbars to all frame not only at a pictrure.Resizing and moving the scrollbars and showing components under when you scroll down.The difficult is that the frame has many components and users can add pictures and admin can add labels or other components,so i don't know what to redraw when the frame is resized.Redraw everything i can't see for example.I paste some code to tell me where i add scrollpane or scrollbar

public class Test extends JFrame {

private JPanel contentPane;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Test frame = new Test();
                frame.setVisible(true);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public Test() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(new SpringLayout());

            //Suppose that here we have many jlabels,jbuttons,jtextfields and other
}

 }

I red some other examples and the problem is that i don't have only a picture to redraw or circles but stuff added by users.Its an online application.

I don't need a small program with a scrollbar example but help on my code how to add it in the entire frame and work dynamically.Resizing and moving the scrollbars and showing components under when you scroll down

Yes you do need a simple example. You should start with something that works and then modify it to meet your needs. You have many problems with your code:

  1. Don't mix AWT and Swing components.
  2. Don't use a null layout.
  3. Don't randomly set the size of a component. Every Swing component is designed to have a preferred size at which is should be displayed.

Read the Swing tutorial . You will find plenty of examples that will show you the proper way to use Swing components and build the initial GUI on the EDT.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM