Layout Problem in a JScrollPane

Hi Friends. I have the following problem.
Fact 1:
When I add components to a JPanel with a FlowLayout, the components rearrange themself to the next line when the length exceeds the viewable area(horizontally).
Goal:
I want to add the JPanel to a scrollPane and I dont want the horizontal scrolling. I want that when I add the components to the JPanel, components are added to the new line, when the horizontal viewable area is used up.(Something like the "fact" mentioned above ... but the difference here is, I want the JPanel inside a JScrollPane)
Problem :
When i add the JPanel to the scrollPane and adds components to JPanel... all components come into one line and don't wraps up themself.
I have also tried with various properties.. telling no horizontal scrollbar etc... but it doesnt helps..... the components are laid off in one single long line.
Please help me with this problem.
Thanks a lot in advance.
Warm Regards,
Nishant

hi friends,
yeah now after a lot of RnD , I am able to implement a solution to the problem... it might not be a good one, but for me it is decent enuf.
I tried everything , extending a custom JPanel from Scrollable and all sorts of things, but nothing was very helpful.
One single thing which is most important is the preferredSize of the JPanel, which if you can set properly with the addition/deletion or resizing ,..... the problem is solved.
so the problem remains only to set the appropiate preferredSize of the Jpanel. unfortunately, the JPanel's respective preferredSize, maximumSize, minimumSize etc are not of much help.
so I decided to look for the components inside the JPanel and look for the last component position and the height.... but unfortunately (I dont know the reason), I get the position of all components, except the last one correct. So my choice of component now is last but one. I calculated the position of last but one component and added the (height of this component + height of last component + some buffer ), to get the height of the panel.
and set the preferredSize of the Jpanel appropiately, for ex. in the action, adding components to the panel.. etc .. etc...
the code snippet is as follows..and it works absolutely fantastic for my requirements, atleast...
Component[] tmpC = _oLeftPanel.getComponents();
if(tmpC.length >1)
     double kbuffer = 25D;
     //doing for last but one comp.
     Component kcomp1 = tmpC[tmpC.length - 2];
     double kh1 = kcomp1.getY();
     kh1 += kcomp1.getHeight();
     kh1 += kbuffer;
     //doing it for the last component
     kcomp1 = tmpC[tmpC.length - 1];
     kh1 += kcomp1.getHeight();
     kh1 += kbuffer;
     Dimension kdim = new Dimension((int)_oLeftScrollPane.getViewport().getViewSize().getWidth(), (int)kh1);
     _oLeftPanel.setPreferredSize(kdim);

Similar Messages

  • Putting a panel using null layout in in a JScrollPane

    Hi,
    I'm trying to create a form for the screen which looks exactly like its equivalent on paper. The form has a grid of cells that can be typed into.
    My approach so far has been to use a JTextPane for each cell and use absolute positioning to put these onto a JPanel with a null layout.
    This has worked well so far, but the JPanel is taller than the screen so I want to put it inside a JScrollPane.
    However the scrollbars don't show up.
    Can someone point out what I need to implement to be able to scroll my null layout JPanel in a JScrollPane.
    Thanks.

    That was nice and simple. The Duke's are yours.
    One problem leads to another unfortunately.
    I want the form to be centered so I put it in another JPanel with BorderLayout then put that in the JScrollPane. Unfortunately it is not centred.
    JPanel nullLayoutPanel = new JPanel();
    nullLayoutPanel.setLayout(null);
    // layout components on panel
    JPanel panelToKeepFormCentered= new JPanel(new BorderLayout());
    panelToKeepFormCentered.add(nullLayoutPanel, BorderLayout.CENTER);
    JFrame frame = new JFrame();
    frame.getContentPane().add(new JScrollPane(panelToKeepFormCentered));Hope it is clear what I'm trying to achieve.
    When the JFrame is smaller than the form (the nullLayoutPanel), scrollbars should show (they do now thanks to Noah).
    When the JFrame is bigger than the form, the form's JPanel should be centred in the JFrame with blank space around.
    Thanks.

  • Problem with the JScrollPane...

    Hi there!
    I have a little problem controling the JScrollPane.
    In some class - which extends the JPanel class - I build the GUI within the constructor.
    This class is later included by another class into the center of a border layout. Now when
    I make this whole window visible, everything looks fine except that the scrollpane scrolled
    down to approx. 3/4 of the panel, but I want the Scrollpane to scroll all the way to the top...
    I already tried to manage this by using
    scrollPane.getVerticalScrollBar().setValue(0);
    But this does not do anything as long as I am calling this function from within the constructor.
    When I trigger this function by pressing some JButton it works fine!
    I guess this has something to do with the way Java paints the Frames and the Panels. And that
    maybe the Scrollpane is not yet existend as such when I try to scroll all the way to the top....
    Do you have any suggestions??
    Thx in advance!!

    But this does not do anything as long as I am calling this function from within the constructor.
    scrollPane.getVerticalScrollBar().setValue(0);Try wrapping the above line in a SwingUtilities.invokeLater(...)
    or maybe using
    component.scrollRectToVisible(...);

  • CSS Layout Problem?

    Can someone please help me with a layout problem.
    As far as I can tell the page looks as it should in Netscape,
    Firefox, etc., but IE6 and 7 refuse to work correctly.
    The page I am working on is:
    http://www.vmtampademo.com/localangler/testpage.html
    Most of the picture caption and headline of the middle column
    is behind the picture. I attempted to force the info with a
    seperating div which seems to work sometimes. I doubt that this is
    the correct solution. What am I doing wrong?
    Thank you for the help!

    It looks fine in Firefox 2.0.0.1, Opera 9.10, and IE 7.

  • Layout problem in PDF conversion

    Hi all,
    i am downloading spool data using the function module CONVERT_ABAPSPOOLJOB_2_PDF. But i am facing layout problem. e.g. RFBILA00(financial statement generation program) has written balancesheet data to the spool. This spool data has some 6 columns. but CONVERT_ABAPSPOOLJOB_2_PDF is writing only first 3 columns to the generated PDF file. i used 'GET_PRINT_PARAMETERS' function module also with values like layout as 'X_65_132' and 'X_90_120'. but no success. if anybody knows the answer, please let me know.
    Thanks in advance,
    Naveen

    Hi All,
    i am following the below approach to download the information from spool.
    program/spool output is an ALV List output data having 8 columns. but below approach is converting only first 5 columns in to PDF format. other 3 columns are getting truncated.
    FUNCTION /ngl/download_spoolinfo_as_pdf.
    ""Local Interface:
    *"  IMPORTING
    *"     REFERENCE(I_SPOOL_REQUEST) LIKE  TSP01-RQIDENT
    *"     REFERENCE(I_FILENAME) LIKE  RLGRAP-FILENAME
    *"  EXCEPTIONS
    *"      DOWNLOAD_ERROR
      TABLES tsp01.
      DATA: mtab_pdf LIKE tline OCCURS 0 WITH HEADER LINE,
            mc_filename LIKE rlgrap-filename.
      DATA: mstr_print_parms LIKE pri_params,
            mc_valid(1) TYPE c,
            mi_bytecount TYPE i.
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        EXPORTING
          copies                 = '1'
          cover_page             = space
          destination            = 'locl'
          expiration             = '1'
          immediately            = space
          mode                   = space
          new_list_id            = 'X'
          no_dialog              = 'X'
          user                   = sy-uname
          line_size              = 200
          line_count             = 65
         layout                 = 'X_65_200'
          layout                 = 'X_90_120'
          sap_cover_page         = 'X'
        IMPORTING
          out_parameters         = mstr_print_parms
          valid                  = mc_valid
        EXCEPTIONS
          archive_info_not_found = 1
          invalid_print_params   = 2
          invalid_archive_params = 3
          OTHERS                 = 4.
      IF sy-subrc EQ 0.
        CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
          EXPORTING
            src_spoolid              = i_spool_request
            no_dialog                = 'X'
            dst_device               = mstr_print_parms-pdest
          IMPORTING
            pdf_bytecount            = mi_bytecount
          TABLES
            pdf                      = mtab_pdf
          EXCEPTIONS
            err_no_abap_spooljob     = 1
            err_no_spooljob          = 2
            err_no_permission        = 3
            err_conv_not_possible    = 4
            err_bad_destdevice       = 5
            user_cancelled           = 6
            err_spoolerror           = 7
            err_temseerror           = 8
            err_btcjob_open_failed   = 9
            err_btcjob_submit_failed = 10
            err_btcjob_close_failed  = 11
            OTHERS                   = 12.
        IF sy-subrc EQ 0.
          mc_filename = i_filename.
          DATA: lv_filename TYPE string.
          lv_filename = i_filename.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
              bin_filesize = mi_bytecount
              filename     = lv_filename
              filetype     = 'BIN'
            TABLES
              data_tab     = mtab_pdf
            EXCEPTIONS
              OTHERS       = 22.
          IF sy-subrc EQ 0.
            WRITE:/ mc_filename, 'CONVERTED TO PDF AND DOWNLOADED'.
          ELSE.
            WRITE:/ 'PROBLEM WITH DOWNLOAD'.
            RAISE download_error.
          ENDIF.
        ELSE.
          WRITE:/ 'PROBLEM WITH PDF CONVERSION'.
          RAISE download_error.
        ENDIF.
      ELSE.
        WRITE:/ 'PROBLEM GETTING PRINT PARAMETERS'.
        RAISE download_error.
      ENDIF.
    ENDFUNCTION.

  • Layout problem - multiple repeating frames

    Hi, I have a layout problem, pls help!
    Short report description:
    - Repeating Frame1 - gives 1 record, contains all other frames, variable vertical elasticity
    - - Frame2 - contains all frames beneath - variable vertical elasticity
    - - - Frame3 - variable vertical elasticity
    - - - - some boilerplates
    - - - - Repeating Frame 2 - various number of records, fixed vertical elasticity, height 100
    - - - - Repeating Frame 3 - various number of records, fixed vertical elasticity, height 30
    - - - - .. other repeating frames ..
    When reaching the bottom of a page, and there is not enough room to print a record for Repeating frame 2, a record from Repeating frame 3 is printed in the bottom.
    Next page starts with the remaining records from Repeating frame 2.. and then the remaining records from Repeating frame 3.
    For example:
    Page 1:
    Rep frame 2 - Record 1
    Rep frame 2 - Record 2
    Rep frame 2 - Record 3
    Rep frame 3 - Record 1 -- not enough space to print Record 4, so this record is printed
    Page 2:
    Rep frame 2 - Record 4
    Rep frame 2 - Record 5
    Rep frame 3 - Record 2
    How can i ensure that all records from Rep frame 2 is printed before records from Rep frame 3?

    Hi, thanks for helping me out!
    I tried to use anchors, but they had no effect when connecting top of 3 to bottom of 2, got the same layout.
    I then tried to create frames with vertical elasticity expand around both rep frame 2 and rep frame 3, and it seems to do the job.
    - Repeating Frame1 - gives 1 record, contains all other frames, variable vertical elasticity
    - - Frame2 - contains all frames beneath - variable vertical elasticity
    - - - Frame3 - variable vertical elasticity
    - - - - some boilerplates
    - - - - Frame 4 - vertical elasticity expand
    - - - - - - Repeating Frame 2 - various number of records, fixed vertical elasticity, height 100
    - - - - Frame 5 - vertical elasticity expand
    - - - - - - Repeating Frame 3 - various number of records, fixed vertical elasticity, height 30
    and so on..
    Thanks again

  • Layout Problem in swings

    I have an Layout problem. My Applications consists of a label and a panel in which some more labels are present.
    The panel should contain the scrollbar in order to view all the label that excced the size of the panel.This label and a panel should be adjacent to each other.
    My problem is, I am not getting the scroll bar to the panel when I am adding the label that excced the size of the panel, when I am adding the label adjacent to this label.

    Did you use JScrollPanel? If not, use it.

  • [solved] layout problem in amarok 2.02

    Hi,
    Here, I have a bad layout problem with amarok 2.02. Amarok does not fit on my screen which is 1400 pixels large! I cannot reduce the part where the collection is shown. So that it is really unpractical to use.
    I uploaded a snapshot to illustrate the problem (it is the full screen!):
    emmanuelfavrenicolin.free.fr/Public/Sna … ok202.jpeg
    Someone have the same problem ?
    I tried to install svn version but I stopped after 3 hours of compilation, it is quite a big application.
    Last edited by manouchk (2009-05-23 06:28:43)

    Well, I tried amarok2-devel 2.0.90-1 but the problem of graphic layout remains similar, no improvement. Is it normall? Maybe amarok is only available for computer with screen >= 1600x1200  or is there an hidden configuration file where I could tweek this?
    Last edited by manouchk (2009-05-18 02:41:03)

  • Urgent: Layout problem in "light inner page"

    Hi Experts,
    I am facing a problem in portal content area on external facing portal. I see a vertical scroll bar which restricts application from being displayed on entire screen.
    I am getting this problem after a patching of EP 7.0, before patching every thing was running fine.
    To me it looks like a layout problem in "light inner page", When I use "Light - 1: column (Full width)" layout I get a vertical scroll bar on portal. When I use default layout then this vertical scroll bar disappears but I see an empty navigation bar on left side which is not required.
    Can some one advise a solution for this.
    -Lave

    hi,
    Similar problem in this thread. check it out
    Desktop inner page lost
    Regardss,
    Ganesh N

  • Div layout problem

    Hi - stuck on what I think should be a fairly basic layout problem:
    I have 2 divs, equal widths but varying heights, one floated to the left and one to the right so that they appear next to eachother on the page.  The one on the left contains varying amounts of text, the one on the right contains a flash player so never varies.
    Where the text for the left div is long, I want it to start off next to the player, but then flow beneath it rather than continuing downwards at the same width as the div.  If I remove the width of the left div, so that it reverts to the container width, the player div positions itself below it, so I can't work out how to get the effect.
    Can anyone help?

    Hi,
    hope I understood in the right way: I used (translated from German DW) "modify table" and so I got one more row and two columns in your Main_Content. In one of the new columns I copied the image and beneath I took the text (you now can replace with image and text of your choice), like this:
    If that's not a help for your question, please ask me again.
    What concerns the width of the pictures, I would format them with PS or a similar program in the same wide.
    Hans-G.

  • Design/Layout Problem in OOTB SP "Docs I'm following" page

    Hello
    The "Docs I'm following" My Sites page in SP 2013 has the following layout problem:
    Long document titles overlap with other elements (see also screenshot).
    Note: This is default SP, i.e. we have not deployed any custom branding.
    I guess this is a problem which can easily be corrected even without having to wait for a SP update. Since I'm not very good with design changes I would be grateful if you could provide
    us with a quick fix, e.g. an updated css file.
    Thanks a lot.
    Best regards
    John

    Hi  ,
    For your issue, you can add the following code into your MySite MasterPage:
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    $(".ms-contentFollowing-itemTitle a").each(function(i){
    $(this).text(shorten($(this).text(),32));
    function shorten(text,maxLength) {
    var ret = text;
    if (ret.length > maxLength) {
    ret = ret.substr(0,maxLength-3) + "...";
    return ret;
    </script>
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • Layout problem with JTabbedPane

    Hi,
    I'm creating a JDialog with a JOptionPane in it which has a JTabbedPane as its ContentPane
    Supposed to look like the pic below. I've put the JOptionPane into a JScrollPane in case the user makes the Dialog too small.
    Problem is that the JTabbedPane stretches to a very large height (way bigger than the dialog height).
    Using setPreferredSIze(..) on the JTabbedPane doesn't help either. If the dialog is made bigger, then the TAbbedPane doesn't stretch, if it is made smaller, the TabbedPane shrinks to the minimum necessary size.
    Any ideas, tips on getting this layout would be appreciated.
    |                                      |/\|
    |  ----- -----                         |--|
    |  |   | |   |                         |  |
    | -----------------------------------  |  |
    | |                                 |  |  |
    | |  2 Tables and several buttons   |  |__|
    | |  on this JTabbedPane using      |  |  |
    | |  GridBagLayout                  |  |__|
    | |                                 |  |  |
    | -----------------------------------  |  |
    |                                      |  |
    |          | OK | | Cancel |           |--|
    |                                      |\/|
    -------------------------------------------

    Check this: http://forum.java.sun.com/thread.jsp?forum=57&thread=293587
    - ananth
    Hi,
    I'm creating a JDialog with a JOptionPane in it which
    has a JTabbedPane as its ContentPane
    Supposed to look like the pic below. I've put the
    JOptionPane into a JScrollPane in case the user makes
    the Dialog too small.
    Problem is that the JTabbedPane stretches to a very
    large height (way bigger than the dialog height).
    Using setPreferredSIze(..) on the JTabbedPane doesn't
    help either. If the dialog is made bigger, then the
    TAbbedPane doesn't stretch, if it is made smaller, the
    TabbedPane shrinks to the minimum necessary size.
    Any ideas, tips on getting this layout would be
    appreciated.
    |                                      |/\|
    |  ----- -----                         |--|
    |  |   | |   |                         |  |
    | -----------------------------------  |  |
    | |                                 |  |  |
    | |  2 Tables and several buttons   |  |__|
    | |  on this JTabbedPane using      |  |  |
    | |  GridBagLayout                  |  |__|
    | |                                 |  |  |
    | -----------------------------------  |  |
    |                                      |  |
    |          | OK | | Cancel |           |--|
    |                                      |\/|

  • Gridbag layout problem on a tabbedpane

    I am not sure whether we can do this or not but, I am trying to have a gridbag layout on a TabbedPane object.
    I have a JFrame on which I am adding a TabbedPane object called "t" and on this TabbedPane I am adding a tab called "Insert" which is an object of class "Insert Data". Then, I add the TabbedPane t on the Container cp, which is inside the JFrame.
    In the InsertData Class (a JPanel), I need to have the gridbag layout. With this gridbag layout object, I am trying to place different objects like buttons, at various places, on this JPanel. But nothing moves on this panel.
    In short, please let me know how can I have a gridbag layout on a Tabbedpane.
    The Main Class is as follows:
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import javax.swing.JFrame;
    import javax.swing.JTabbedPane;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class Main extends JFrame implements ActionListener, ChangeListener{
         Main(){
                   setPreferredSize(new Dimension(1200,600));
                   Container cp = getContentPane();
                   JTabbedPane t = new JTabbedPane();
                   // insert
                   InsertData insertOptions = new InsertData();
                   t.addTab("Insert",insertOptions);
                   cp.add(t);
                   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   pack();
                   setVisible(true);
              @Override
              public void actionPerformed(ActionEvent arg0) {
                   // TODO Auto-generated method stub
              @Override
              public void stateChanged(ChangeEvent arg0) {
                   // TODO Auto-generated method stub
              public static void main(String args[]){
                   new Main();
         }The InsertDataClass is:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class InsertData extends JPanel{
         InsertData(){
              setPreferredSize(new Dimension(1200,600));
              setBackground(Color.blue);
              //setLayout(new GridBagLayout());
              GridBagLayout gb = new GridBagLayout();
              setLayout(gb);
              GridBagConstraints c = new GridBagConstraints();
              //c.insets = new Insets(2, 2, 2, 2);
              //JPanel p1= new JPanel();
              //p1.setPreferredSize(new Dimension(200,200));
              JButton b1 = new JButton("here i am!!!");
              //p1.add(b1);
              //c.fill = GridBagConstraints.HORIZONTAL;
              //c.anchor = GridBagConstraints.WEST;
              c.gridx=0;
              c.gridy=1;
              add(b1,c);
    }

    how can I have a gridbag layout on a Tabbedpane.Huh? You post an example with just one JButton and no weightx / weighty set and you expect others here to be able to see a problem with your layout?
    Also, there's needless, unused code that is just clutter -- like the unimplemented ActionListener and ChaneListener. Recommended reading: [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://mindprod.com/jgloss/sscce.html].
    Finally, I don't see any need whatsoever to extend JFrame and JPanel as you are not introducing any new behavior of either. Always favor composition over inheritance.
    I plugged in some code I had used for someone else's GridBagLayout problems and this will show you that there's no difference in using GridBagLayout in a tabbed pane component or anywhere else.import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import javax.swing.*;
    public class GridBagInTabbedPane {
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            new GridBagInTabbedPane().makeUI();
      public void makeUI() {
        Font fontButton = new Font("Arial", Font.BOLD, 10);
        Font fontLabel = new Font("Arial", Font.BOLD, 15);
        JLabel labelEnter = new JLabel("Enter sentences in the text area ");
        labelEnter.setFont(fontLabel);
        JTextArea textArea = new JTextArea();
        textArea.setPreferredSize(new Dimension(630, 280));
        JScrollPane scrollPane = new JScrollPane(textArea);
        scrollPane.setMinimumSize(new Dimension(630, 280));
        JLabel labelDuplicates = new JLabel("Duplicates will appear here");
        labelDuplicates.setMinimumSize(new Dimension(650, 30));
        labelDuplicates.setFont(fontLabel);
        JButton buttonDisplay = new JButton("Display Map");
        buttonDisplay.setFont(fontButton);
        JButton buttonClear = new JButton("Clear");
        buttonClear.setFont(fontButton);
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 2;
        gbc.fill = GridBagConstraints.NONE;
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.insets = new Insets(5, 5, 5, 5);
        gbc.weightx = 0.5;
        panel.add(labelEnter, gbc);
        gbc.gridy = 1;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.weighty = 0.5;
        panel.add(scrollPane, gbc);
        gbc.gridy = 2;
        gbc.fill = GridBagConstraints.NONE;
        gbc.weighty = 0.0;
        panel.add(labelDuplicates, gbc);
        gbc.gridy = 3;
        gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.EAST;
        panel.add(buttonDisplay, gbc);
        gbc.gridx = 1;
        gbc.anchor = GridBagConstraints.WEST;
        panel.add(buttonClear, gbc);
        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.add(panel);
        JFrame frame = new JFrame();
        frame.add(tabbedPane);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }db

  • Please help ! LAYOUT - PROBLEMS

    Hi !
    I have a big problem with using the rigth layoutmanager for my GUI.
    I have a JScrollPane and want to add several JPanels to it. These Panels should have to same width, but different height. So I used a GridBagLayout and it works good.
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(10,2,5,2);
    JPanel inputPanel = new JPanel(layout);
    c.gridwidth = GridBagConstraints.REMAINDER;
    // add several lines to inputPanel
    JPanel line;
    line = new JPanel(new GridLayout(1,2));
    layout.setConstraints(line,c);
    inputPanel.add(line);
    line = new JPanel(new GridLayout(1,2));
    layout.setConstraints(line,c);
    inputPanel.add(line);
    line = new JPanel(new GridLayout(1,2));
    layout.setConstraints(line,c);
    inputPanel.add(line);
    scroll = new JScrollPane(inputPanel);
    But another property should be that the width should be tried on at the current size of the JScollPane. So I used a GridLayout and the width of my JPanel's were good, but of course they all had the same height.
    GridLayout layout = new GridLayout(0,1);
    JPanel inputPanel = new JPanel(layout);
    // add several lines to inputPanel
    JPanel line;
    line = new JPanel(new GridLayout(1,2));
    layout.setConstraints(line,c);
    inputPanel.add(line);
    line = new JPanel(new GridLayout(1,2));
    layout.setConstraints(line,c);
    inputPanel.add(line);
    line = new JPanel(new GridLayout(1,2));
    layout.setConstraints(line,c);
    inputPanel.add(line);
    scroll = new JScrollPane(inputPanel);
    Is there a possibility to have both properties ( different height and conformed width) ?
    Thanks very much for help !

    hi,
    Yes it's possible. keep working with the gridbaglayout.
    There are constraints where you can set X and Y behaviour like : every component must have the same width but own height. I don't know the constraint's name because I work with a visual gridbaglayout editor.
    Xavier

  • Using null Layout - Problems

    Hullo - I've written a little app that, because of the nature of what it does, prettymuch requires the use of null layout. It works well enough, but there are a few points where it does strange things that I don't understand. I haven't been able to find any good docs anywhere for how exactly layout/rendering works. The Swing tutorial, for example, almost completely ignores the topic.
    Basically, I set the layout to null, add my components, use setBounds...but then nothing happens. In order for anything to be visible, I have to call pack() before I call show(). What is pack? What does it do? How can Sun's null layout examples work even though most of them don't use it?
    Second, if I create JFrame of a certain size, and add a component that goes off the bottom of the JFrame (on purpose), then expand the size of the JFrame to reveal the bottom part of that component, it doesn't paint - there's just a grey area. No amount of repaint() pack() or anything will cause it to show. The only way I've found to do it is to make the JFrame larger to begin with, add the component so that it's visible, then resize to the smaller size, which is kind of ugly and clunky.
    I basically do not understand why Swing is doing the things it does; why it paints sometimes and not other times, where it paints, when it paints, where it shows objects, how it packs them, etc. I would be very grateful if someone could englighten me!

    Hullo - I've written a little app that, because of the
    nature of what it does, prettymuch requires the use of
    null layout. It works well enough, but there are a
    few points where it does strange things that I don't
    understand. I haven't been able to find any good docs
    anywhere for how exactly layout/rendering works. The
    Swing tutorial, for example, almost completely ignores
    the topic.
    Basically, I set the layout to null, add my
    components, use setBounds...but then nothing happens.
    In order for anything to be visible, I have to call
    pack() before I call show(). What is pack? What
    does it do? How can Sun's null layout examples work
    even though most of them don't use it?
    Second, if I create JFrame of a certain size, and add
    a component that goes off the bottom of the JFrame (on
    purpose), then expand the size of the JFrame to reveal
    the bottom part of that component, it doesn't paint -
    there's just a grey area. No amount of repaint()
    pack() or anything will cause it to show. The only
    way I've found to do it is to make the JFrame larger
    to begin with, add the component so that it's visible,
    then resize to the smaller size, which is kind of ugly
    and clunky.
    I basically do not understand why Swing is doing the
    things it does; why it paints sometimes and not other
    times, where it paints, when it paints, where it shows
    objects, how it packs them, etc. I would be very
    grateful if someone could englighten me!Okay, I think you should call setVisible(true); instead of pack then show. Pack basically organizes the components so they take up the least amount of room, and then it shrinks the frame to as small as it will go without hiding any components. It think if you call revalidate() instead of repaint(), should solve your problem.
    The other thing to do, is (hehe) make your own components

Maybe you are looking for