0
votes

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.

1
1- Why AWT? It's an out-of-date API; 2- Take a look at ScrollPane - Second hit from Google; 3- null layouts WILL NOT HELP YOU with this problemMadProgrammer
I know about null layouts but how i suppose to put everything to the place i like?Can i have scrollbars with null layout?GiorgosM
Either with an appropriate layout manager or compound layout managers. "Can i have scrollbars with null layout?" - Not easily. The ScrollPane relies on information provided to it by the layout manager to determine the overalls size of the component it contains so it make decisions about when it should display the scrollbarsMadProgrammer

1 Answers

1
votes

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.