Results 1 to 9 of 9
  1. #1
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default Can I add scrollPane to panel with not access to the frame

    I have JPanel - but don't have access to the "father" - I mean waht the jPanel is added to ( JFrame or something else)

    I want to add JSrollPanel but all the example I see are something like that

    Java Code:
    JScrollPane scrollPane = new JScrollPane(myJPanel);
    myJFramel.add( scrollPane, BorderLayout.CENTER );
    Is there a way to add a scroll to a component itself ithout its paranet?

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default

    The problem is that I cannot use myFrame - only the Panel
    the code is and example of how to use JScrollPane. when I try

    Java Code:
    JScrollPane scrollPaneOut = new JScrollPane();
    myPanel.add(scrollPaneOut,null);
    or

    JScrollPane scrollPaneOut = new JScrollPane(myPanel);
    myPanel.add(scrollPaneOut,null);
    I imply don't have the scroll bars so its not working

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually what you have to do is, first add components to the JPanel if any. Then add that panel into the JScrollPane. Finally add that panel to the frame.

  5. #5
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default

    ok . I have many components in the panel - and I need scroll for the panel so I can move between these buttons and textfield when I'm not using full screen -

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Try this simple code segment.

    Java Code:
        public static void main(String[] args) {
            JFrame frame = new JFrame();
    
            JPanel panel = new JPanel();
            panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    
            for(int i = 0; i < 10; i++) {
                panel.add(new JButton("JButton"));
            }
    
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new JScrollPane(panel));
            frame.setSize(200,200);
            frame.setVisible(true);
            frame.setLocationRelativeTo(null);
        }

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  9. #9
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default

    Again - the problem - I dont have access to the JFrame- only to the panel.
    I look several times on the scrollpane toturial in "sun" .

    I control only the frame - other part of the program, which I cannot change or modify , add the panel to the frame. It is not that simple.

    Java Code:
    public static void main(String[] args) {
           [COLOR="Red"][B] JFrame frame = new JFrame();[/B][/COLOR]
    //  I cant access JFrame. 
    
    //from here my program starts
            JPanel panel = new JPanel(); // 
    
            panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    
            for(int i = 0; i < 10; i++) {
                panel.add(new JButton("JButton"));
            }
    
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new JScrollPane(panel));
            frame.setSize(200,200);
            frame.setVisible(true);
            frame.setLocationRelativeTo(null);
        }

Similar Threads

  1. Method access or field access
    By carderne in forum New To Java
    Replies: 2
    Last Post: 12-06-2008, 07:20 PM
  2. ScrollPane Issues..
    By hanifa in forum AWT / Swing
    Replies: 4
    Last Post: 09-11-2008, 09:18 AM
  3. scrollpane
    By Newb in forum AWT / Swing
    Replies: 0
    Last Post: 06-09-2008, 01:14 AM
  4. Tree with Listener not working when added to ScrollPane
    By praveen.kb in forum AWT / Swing
    Replies: 2
    Last Post: 01-09-2008, 08:06 AM
  5. How to place panel into frame
    By vivek_9912 in forum AWT / Swing
    Replies: 2
    Last Post: 11-20-2007, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •