-1

First of all, I've gone through this related question, but couldn't get it working.

Now, My question: I have a JFrame, containing a JPanel inside, which is drawn dynamically. Now, when i draw this panel, it occupies entire screen, and spreads to the edges. I have used BoxLayout.Y_AXIS on the panel.

How van i achieve this...

I have attached the screenshots:

What I Got: What i got

What I want:

What i want

EDIT: Adding source codes(minimized, not actual)

public class DialogReportsMain extends JDialog implements ActionListener 
{
  public DialogReportsMain(JFrame mParent, boolean isModal) 
  {  
  /*******************************************/

  setLayout(new BorderLayout(0, 0));

      /***************************************/
      addNorthContent(this);
      addWestContent(this);
      addSouthContent(this);

      /***************************************/
  JPanel mOrderHeaderContainer = new JPanel();
    mOrderHeaderContainer.setLayout(new BoxLayout(mOrderHeaderContainer, BoxLayout.Y_AXIS));

        /***************************************/
        // Table Number
        JLabel mLabelTableNumber = new JLabel("Table: "
                                                + new Integer(mOrderDetails.mTableNumber).toString());
        mOrderHeaderContainer.add(mLabelTableNumber);

        /***************************************/
        // Dates
        JPanel mPanelDates = new JPanel();
        mPanelDates.setLayout(new GridLayout(1, 2, 20, 0));

            JLabel mLabelReceivedDateTime = new JLabel(mOrderDetails.mReceivedDateTime);
            mPanelDates.add(mLabelReceivedDateTime);

            JLabel mLabelBillDateTime = new JLabel(mOrderDetails.mBillDateTime);
            mPanelDates.add(mLabelBillDateTime);

        mOrderHeaderContainer.add(mPanelDates);

        /***************************************/
        // Waiter Details
        JLabel mLabelWaiterDetails = new JLabel("Waiter: "
                                                + new Integer(mOrderDetails.mWaiterId).toString()
                                                + " ("
                                                + mOrderDetails.mWaiterName
                                                + " )"
                                                );
        mOrderHeaderContainer.add(mLabelWaiterDetails);

        /***************************************/
        // Blank Lines
        mOrderHeaderContainer.add(new JLabel());
        mOrderHeaderContainer.add(new JLabel());

    /***************************************/
            add(mOrderHeaderContainer, BorderLayout.CENTER);


  /*******************************************/
  setTitle("Reports");
  setModalityType(ModalityType.MODELESS);
  setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  setResizable(true);
  setMinimumSize(new Dimension(100, 400));
  makeDialogFullScreen(this);
  setLocationRelativeTo(null);
  }
}
Community
  • 1
  • 1
Nitin Bansal
  • 2,986
  • 3
  • 23
  • 30
  • You can call pack() on the JFrame to pack it into the best fitting window. – mino Apr 18 '12 at 11:11
  • @mino : the container of panel which i intent to "pack" is also a panel, and that is nested to a great extent. So, in that case will ur suggestion work? – Nitin Bansal Apr 18 '12 at 11:13
  • I believe it should work if you call pack on the Actual JFrame and have no size constraints set on your JPanels. – mino Apr 18 '12 at 11:18
  • 2
    Also, it DOES help if you provide the code you've used instead of an image. Then we can help tell you where you've gone wrong. :-) – mino Apr 18 '12 at 11:19
  • @mino : my parent JFrame is set to full screen, by explicitly setting size. So, I guess this will not work as u pointed out " – Nitin Bansal Apr 18 '12 at 11:20
  • 1
    My gut impression is that you haven't given enough information to make this question answerable yet. – Hovercraft Full Of Eels Apr 18 '12 at 11:27
  • @HovercraftFullOfEels : I realized dat, hence, i've added the code...can u plz suggest solution now – Nitin Bansal Apr 18 '12 at 11:31
  • 3
    I suggest you spell words like 'that', 'you' & 'please' properly & post an [SSCCE](http://sscce.org/). – Andrew Thompson Apr 18 '12 at 11:33

1 Answers1

1
  • method pack() finalize output to the screen based on

    a) used LayoutManager

    and

    b) Size/PrefereredSize

    retured from all elements in the current Component's hierarchy

  • BoxLayout accepting by default Size/PrefereredSize, notice this attribute could be different implemented for every of LayoutManagers

mKorbel
  • 109,525
  • 20
  • 134
  • 319