Layout question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Layout question

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Posts
    4

    Layout question

    Hello all,

    I want to create an application that will have navigation in a fixed width flexible length bordered rectangle on the left side of the application window with the main part of the application in a bordered area (flexible width and length) to the right of the navigation rectangle. There should be same space between the navigation border and the main area border. The navigation will be buttons with a brief description under them. For anyone using Firefox, i'm trying to get the exact same layout as what you get when you choose Tools-->Options.

    Which layout manager do i have to use to get this kind of layout and do i have to use the borderfactory to create the borders around the navigation and main area of the application?

    Thanks.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    It shouldn't be that complicated

    Ive done this with htree splitPanes.

    Just one thing, if the main part is flexible w & h then the left part (the
    the navigation) must be flexible width too, or else you get some realestate
    on the screen that is not accounted for....

    And if you want the left & main part to have flexible height then that leaves
    you with two empry spaces (emptyPan1 & emptyPan2).

    Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    /**
     * An Application Layout Template
     */
    
    public class AppFrame extends JFrame {
      JSplitPane mainSplitPane = new JSplitPane();
      JSplitPane leftSplitPane = new JSplitPane();
      JSplitPane rightSplitPane = new JSplitPane();
    
      JPanel navPanel = new JPanel();
      JPanel emptyPan1 = new JPanel();
    
      JPanel contentPanel = new JPanel();
      JPanel emptyPan2 = new JPanel();
      JLabel statusLbl = new JLabel();
    
      public AppFrame() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      public static void main(String[] args) {
        AppFrame appFrame = new AppFrame();
        appFrame.setBounds(20,20,600,500);
        appFrame.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
        appFrame.setVisible(true);
      }
      private void jbInit() throws Exception {
        leftSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
        rightSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
        this.setTitle("Standard App Layout");
        statusLbl.setBorder(BorderFactory.createEtchedBorder());
        statusLbl.setText("That\'s it....?");
        this.getContentPane().add(mainSplitPane, BorderLayout.CENTER);
        mainSplitPane.add(leftSplitPane, JSplitPane.LEFT);
        leftSplitPane.add(navPanel, JSplitPane.TOP);
        leftSplitPane.add(emptyPan1, JSplitPane.BOTTOM);
        mainSplitPane.add(rightSplitPane, JSplitPane.RIGHT);
        rightSplitPane.add(contentPanel, JSplitPane.TOP);
        rightSplitPane.add(emptyPan2, JSplitPane.BOTTOM);
        this.getContentPane().add(statusLbl, BorderLayout.SOUTH);
        leftSplitPane.setDividerLocation(250);
        mainSplitPane.setDividerLocation(170);
        rightSplitPane.setDividerLocation(250);
      }
    }
    eschew obfuscation

Similar Threads

  1. Replies: 1
    Last Post: 11-18-2002, 02:23 PM
  2. Display one record at a time!
    By ASP learner in forum ASP.NET
    Replies: 5
    Last Post: 10-08-2002, 08:17 PM
  3. grid layout question.
    By in forum Java
    Replies: 0
    Last Post: 05-30-2002, 10:32 AM
  4. swing Null layout
    By satish in forum Java
    Replies: 6
    Last Post: 10-16-2001, 09:06 PM
  5. Box Layout Question: JTextFields bloated
    By David Stevenson in forum Java
    Replies: 0
    Last Post: 11-25-2000, 10:18 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center