1 Reply Latest reply: Mar 11, 2014 3:29 AM by PhHein RSS

    JScrollPane problems

    Robinwood

      Hello. I have been trying to get the JScrollPane working on this project with little success. The problem is, the center panel draws a picture based on user dimensions and the picture can get quite big, which draws partially off screen. Is there a way to add a scrollpane to the entire frame or individual panels based on the redrawn size? If so, how do I apply it to the specific code shown below?

       

      import java.awt.BorderLayout;

      import java.awt.Toolkit;

      import java.io.File;

      import java.io.IOException;

       

       

      import javax.imageio.ImageIO;

      import javax.swing.JFrame;

      import javax.swing.JPanel;

      import javax.swing.JScrollPane;

       

       

      /**

      * This class constructs the frame on screen.

      */

      public class DViewer extends JFrame {

       

        private static JFrame frame;

        private static JPanel dDPanel;

       

        /**

        * Construct  frame and panels

        */

        public DViewer() {

        super();

       

       

        frame = new JFrame();

       

       

        frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());

        frame.setTitle("Designer");

        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

       

        dDPanel = new JPanel(new BorderLayout());

        dDPanel.add(new DComponent(), BorderLayout.CENTER);

        dDPanel .add(new UserDI(), BorderLayout.NORTH);

        dDPanel .add(new USOptions(), BorderLayout.WEST);

        dDPanel .add(new Selecter(), BorderLayout.SOUTH);

       

       

        JScrollPane scrollPane = new JScrollPane();

        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

       

        frame.add(dDPanel );

        frame.setVisible(true);

        }

       

        public static void repaintD() {

        BorderLayout layout = (BorderLayout) dDPanel.getLayout();

        dDPanel.remove(layout.getLayoutComponent(BorderLayout.CENTER));

        dDPanel add(new DeckComponent(), BorderLayout.CENTER);

       

        frame.revalidate();

        frame.repaint();

        }

       

      }