need help with Frame & Scrollbar

Discussion in 'Java' started by Jenny, Aug 12, 2004.

  1. Jenny

    Jenny Guest

    Hi,

    I found an old post under this title. The code had some error so I
    change it a little. But when I run it, it has an empty window and I
    cannot close it. How can I display the 2 buttons with the scroll
    bars?
    Why is the exit control button not working?

    Thanks a lot.


    Here is my code:


    import java.awt.*;
    import javax.swing.*;
    class Scroll {
    public static void main(String[] args){

    Frame f = new Frame ("Demo");
    JScrollPane s = new JScrollPane();
    Panel p = new Panel();
    Button b1 = new Button("Button 1");
    Button b2 = new Button("Button 2");

    f.add("Center", s);
    s.add(p);
    p.add(b1);
    p.add(b2);
    f.setSize(200,200);
    f.setVisible(true);
    }}
     
    Jenny, Aug 12, 2004
    #1
    1. Advertising

  2. Jenny

    Jenny Guest

    Sorry, in my code, I should only use swing objects. Here is new code.

    import java.awt.*;
    import javax.swing.*;
    class Scroll {
    public static void main(String[] args){

    Frame f = new Frame ("Demo");
    JScrollPane s = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    JPanel p = new JPanel();
    JButton b1 = new JButton("Button 1");
    JButton b2 = new JButton("Button 2");
    p.add(b1);
    p.add(b2);
    s.add(p);
    f.add("Center", s);
    f.setSize(200,200);
    f.setVisible(true);
    }}
     
    Jenny, Aug 13, 2004
    #2
    1. Advertising

  3. On 12 Aug 2004 17:27:38 -0700, Jenny wrote:

    <http://www.physci.org/codes/javafaq.jsp#cljg>

    > Sorry, in my code, I should only use swing objects. Here is new code.

    ....

    > Frame f = new Frame ("Demo");


    JFrame f = new JFrame("Demo");

    You will find the behaviour of the code changes,
    and you should no longer simply f.add( component )

    Read up on both in the JAvaDocs.
    <http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFrame.html>

    ....
    > f.add("Center", s);


    f.add(s, BorderLayout.CENTER);

    <http://java.sun.com/j2se/1.4.2/docs/api/java/awt/BorderLayout.html>

    ...where did you get that crappy code?

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Aug 13, 2004
    #3
  4. On Fri, 13 Aug 2004 04:53:26 GMT, Andrew Thompson wrote:

    > f.add(s, BorderLayout.CENTER);


    Or rather, since this is a JFrame and I had
    specifically commented on it above..

    f.getContentPane().add(...);

    [ D'uhh! ]

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Aug 13, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul J. Le Genial

    horizontal scrollbar problem in frame with IE

    Paul J. Le Genial, Mar 9, 2005, in forum: HTML
    Replies:
    13
    Views:
    2,412
    Paul J. Le Genial
    Mar 14, 2005
  2. Replies:
    1
    Views:
    1,006
  3. jakeatkins
    Replies:
    3
    Views:
    456
    jakeatkins via WebmasterKB.com
    Jul 23, 2007
  4. Alex

    ScrollBar? Does it exist just WEB ScrollBar Control?

    Alex, Apr 1, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    299
    Alvin Bruney [MVP]
    Apr 4, 2004
  5. Roberto
    Replies:
    4
    Views:
    141
    Roberto
    Apr 6, 2004
Loading...

Share This Page