Results 1 to 11 of 11
  1. #1
    Caspar is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default AbsoluteLayout inside a JScrollPane

    I'm using setLayout(new AbsoluteLayout ()) for an app where I have to have absolute control over the size & position of every item on the screen. No problems except for scrolling. Does anyone have sample code where this combination (AbsoluteLayout inside a JScrollPane) works?

  2. #2
    Tamasa is offline Member
    Join Date
    Aug 2011
    Posts
    7
    Rep Power
    0

    Default

    AbsoluteLayout is using the default bounds of jScrollPane of (0,0,0,0).

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    To get better help sooner, post a SSCCE that clearly demonstrates your problem.

    db

  4. #4
    Caspar is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks Tamasa, do you have sample code to show how to overcome this?

  5. #5
    Caspar is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    Good Idea Darryl. Here is some code that replicate the issue I have. When you resize the window all is well, but when you scroll nothing comes into view.

    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import java.awt.Panel;
    import javax.swing.JTextField;
    import javax.swing.ScrollPaneConstants;
    import org.netbeans.lib.awtextra.AbsoluteConstraints;
    import org.netbeans.lib.awtextra.AbsoluteLayout;

    public class AbsoluteLayoutInsideJScrollPane {
    private JFrame aBsoluteLayoutFrame;
    private JScrollPane cellJScrollPane;
    private Panel cellPanel;

    public AbsoluteLayoutInsideJScrollPane(){
    cellPanel = new Panel();
    cellPanel.setLayout(new AbsoluteLayout ());

    // Add 100 JTextFields to cellpanel
    for (int n = 0; n<100; n++) { cellPanel.add(new JTextField(" TextField - "+n), new AbsoluteConstraints(n*20,n*50,100,20)); }

    cellJScrollPane = new JScrollPane(cellPanel);
    cellJScrollPane.setVerticalScrollBarPolicy(ScrollP aneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    cellJScrollPane.setHorizontalScrollBarPolicy(Scrol lPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    cellJScrollPane.setBounds(0,0,650,650);
    cellJScrollPane.setViewportView(cellPanel);
    cellJScrollPane.setVisible(true);
    cellJScrollPane.repaint();
    cellJScrollPane.validate();
    aBsoluteLayoutFrame = new JFrame("Absolute Layout Inside JScrollPane");
    aBsoluteLayoutFrame .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aBsoluteLayoutFrame.add(cellJScrollPane);
    aBsoluteLayoutFrame.setSize(650, 650);
    aBsoluteLayoutFrame.setVisible(true);
    }
    }

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    I don't see the class AbsoluteLayout either in your posted code or the JDK, so your posted code isn't a SSCCE.

    db

  7. #7
    Caspar is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    import org.netbeans.lib.awtextra.AbsoluteLayout;

  8. #8
    Caspar is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    My son came up with the solution: I was using Panel instead of JPanel...

    Thanks anyway.

    ;-)

  9. #9
    dik05 is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default

    first u have to put JScrollPane and than put Panel on it and make panel Absolute.....

    i hope it works...

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Quote Originally Posted by dik05 View Post
    first u have to put JScrollPane and than put Panel on it and make panel Absolute.....

    i hope it works...
    Meaningless response to an already resolved thread. Please don't do this again.

    db

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Quote Originally Posted by Caspar View Post
    import org.netbeans.lib.awtextra.AbsoluteLayout;
    Not part of the JDK. Did you read the SSCCE web page? Using non standard classes won't get you better help sooner.

    db

Similar Threads

  1. JList inside JScrollPane is not displaying
    By _SAS in forum AWT / Swing
    Replies: 2
    Last Post: 07-31-2011, 08:45 PM
  2. Replies: 9
    Last Post: 04-12-2011, 07:26 PM
  3. JScrollPane
    By UJJAL DHAR in forum New To Java
    Replies: 12
    Last Post: 08-17-2010, 06:47 PM
  4. Heavyweight Component resizing inside JScrollpane
    By random7 in forum AWT / Swing
    Replies: 2
    Last Post: 07-20-2010, 01:58 PM
  5. how to draw an image inside of jscrollpane
    By paty in forum Java Applets
    Replies: 1
    Last Post: 07-24-2007, 12:44 AM

Tags for this Thread

Posting Permissions

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