Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Boder layout model needed

Posted on 2004-04-13
16
Medium Priority
?
343 Views
Last Modified: 2010-03-31
Hi every one,
         I need a boder layout model which looks something  like this :
 
                           (north)
                    command button

                     (center)       (west)
(east)          jtextarea-1      jsplitpane (vertical)
jcombo       jtextarea-2         jtree
box  

                           south
                      commandbutton
can anybody provide a coding for the above.I really have problem while using all the 5 regions of the boder layout.
Thank you.
                       
0
Comment
Question by:clearme1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
16 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 10811595
Start with making a JPanel for all of your 5 regions. (Don't add the button, boxes,... directly into the border layout)

So,

e.g. for your buttons in the north/south

JPanel mainPanel = new JPanel( new BorderLayout() );

JPanel southPanel = new JPanel(); // is FlowLayout/Center by default
southPanel.add(new JButton("My button in the south") );
mainPanel.add(southPanel, BorderLayout.SOUTH);

JPanel northPanel = new JPanel(); // is FlowLayout/Center by default
northPanel.add(new JButton("My button in the north") );
mainPanel.add(northPanel, BorderLayout.NORTH);

Do the same for your west (=left!), center and east (=right!) panels.



0
 
LVL 37

Expert Comment

by:zzynx
ID: 10811620
Doing it this way you can decide to put your buttons in the center or at the left or right by

Center:
JPanel southPanel = new JPanel();

Left:
JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)));

Right:
JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)));
0
 

Author Comment

by:clearme1
ID: 10812221
Hi zzynx,
  I have tried the following code.I am getting blank screen as the result.
I have tried the follwing:

north:
1 jbutton
center
1 text area
west
1 jtree
south
1 jbutton

Can u plz make necessary corrections.
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;


public class client1 extends JFrame {


   JFrame clientframe;
   JButton open,top;
   JTextArea showfile;
   JTree tree3;
   JFileChooser chooserdialog;
   FileReader choosefile;
 
         DefaultMutableTreeNode root=new DefaultMutableTreeNode("chatting Clients");
    DefaultMutableTreeNode child1;
    DefaultMutableTreeNode child2;
    DefaultMutableTreeNode child3;
    DefaultMutableTreeNode child4;
    DefaultMutableTreeNode child5;

   client1(){
         clientframe=new JFrame("CLIENT");
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        


         JPanel clientpanel=new JPanel(new FlowLayout());
         JPanel clientpanel1=new JPanel(new FlowLayout());
         JPanel clientpanel2=new JPanel(new FlowLayout());
          
         JLabel framename=new JLabel("client frame");
       
       child1=new DefaultMutableTreeNode("jenifer");
       child2=new DefaultMutableTreeNode("britney");
       child3=new DefaultMutableTreeNode("maria");
       child4=new DefaultMutableTreeNode("christina");
       child5=new DefaultMutableTreeNode("jones");
       root.add(child1);
          root.add(child2);
       root.add(child3);
       root.add(child4);
       root.add(child5);
       tree3 = new JTree(root);
     

       showfile=new JTextArea(50,50);
       
       clientpanel2.add(tree3);
       getContentPane().add(new JScrollPane(showfile),BorderLayout.CENTER);
        getContentPane().add(clientpanel2,BorderLayout.WEST);


       open=new JButton("OPEN");
       top=new JButton("top");
     
       clientpanel.add(top);
       clientpanel1.add(open);
       

       
     
       getContentPane().add(clientpanel,BorderLayout.NORTH);
       getContentPane().add(clientpanel1,BorderLayout.SOUTH);
     

       show();
       setSize(640,480);

    }
       


    public static void main(String args[]){
            new client1();
      
    }
}


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:clearme1
ID: 10812702
Hi zzynx,
  Are u their?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10812719
I'm back. Sorry.
Looking...
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10812742
add

               pack();

before

               show();
0
 

Author Comment

by:clearme1
ID: 10812751
No problem!happy that u r back.
0
 

Author Comment

by:clearme1
ID: 10812954
hI zzynx,
     i am getting the output now.I still need ur help.why the use of pack()?I need an explanation for that!I also want to add jsplitpane in the west and then put jtree in it.In my code i have simply added jtree in the west.Can u plz help me.
0
 

Author Comment

by:clearme1
ID: 10813278
Hi zzynx,
     r u their!!!!!!!!!!!
0
 
LVL 37

Accepted Solution

by:
zzynx earned 200 total points
ID: 10813319
I am!
But... - you'll never guess - I have some other work to do too... ;)
Be patient.

about the pack().
This is what the java help says:

"Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.
If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated."

If you don't pack, I think all your components are of size 0.

About splitpane:
This might help, although I'm not completely satisfied. (the scrollpane around the tree doesn't "work" yet)

import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;


public class client1 extends JFrame {


   JFrame clientframe;
   JButton open,top;
   JTextArea showfile;
   JTree tree3;
   JFileChooser chooserdialog;
//   FileReader choosefile;
 
        DefaultMutableTreeNode root=new DefaultMutableTreeNode("chatting Clients");
    DefaultMutableTreeNode child1;
    DefaultMutableTreeNode child2;
    DefaultMutableTreeNode child3;
    DefaultMutableTreeNode child4;
    DefaultMutableTreeNode child5;

   client1(){
        clientframe=new JFrame("CLIENT");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       


        JPanel clientpanel=new JPanel(new FlowLayout());
        JPanel clientpanel1=new JPanel(new FlowLayout());
        JPanel clientpanel2=new JPanel(new FlowLayout());
         
        JLabel framename=new JLabel("client frame");
       
       child1=new DefaultMutableTreeNode("jenifer");
       child2=new DefaultMutableTreeNode("britney");
       child3=new DefaultMutableTreeNode("maria");
       child4=new DefaultMutableTreeNode("christina");
       child5=new DefaultMutableTreeNode("jones");
       root.add(child1);
       root.add(child2);
       root.add(child3);
       root.add(child4);
       root.add(child5);
       tree3 = new JTree(root);
     

       showfile=new JTextArea(50,50);
       
       JScrollPane theScrollPane = new JScrollPane();
       theScrollPane.setViewportView(tree3);
       clientpanel2.add(theScrollPane);
       getContentPane().add(new JScrollPane(showfile), BorderLayout.CENTER);
       
       
       JSplitPane theSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
       theSplitPane.setResizeWeight(0.33);
       theSplitPane.setBottomComponent(clientpanel2);
       theSplitPane.setTopComponent(new JLabel("Top here"));
       
       getContentPane().add(theSplitPane, BorderLayout.WEST);


       open=new JButton("OPEN");
       top=new JButton("top");
     
       clientpanel.add(top);
       clientpanel1.add(open);
       

       
     
       getContentPane().add(clientpanel,BorderLayout.NORTH);
       getContentPane().add(clientpanel1,BorderLayout.SOUTH);
     
       pack();
       show();
       setSize(640,480);

    }
       


    public static void main(String args[]){
          new client1();
     
    }
}
0
 

Author Comment

by:clearme1
ID: 10813372
Very sorry for not being patient.My friends told me that reponses are quick,that's why i got anxious.
I will see the code send by u and return.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10813428
>> My friends told me that reponses are quick
Very often they are. Sometimes they aren't.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10813443
>> Very sorry for not being patient
Never mind.
I like this more than people asking questions and afterwards you don't hear *anything* of them.
0
 

Author Comment

by:clearme1
ID: 10813586
Being a stranger u r helping me.So,it's my duty to give u full respect and ofcourse time to solve questions.I run the program send by u.It's working.Through this i will start learning
about JSplitpane.Information regarding pack()
was very timely as i have been facing some problems for 3 days now.The session with u was very knowledgeable and i hope to learn few things from it.
Thank you.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10813743
Thanks for accepting.
:°)
That makes us answering your future questions too.
0
 

Author Comment

by:clearme1
ID: 10813810
I am very glad that u r willing to answer my future questions.I really need support from EE for learning java.Ur
last comment was really encouraging and i am looking forward to have good time with EE.Thank you once again for
participating in my question.
Thank you.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question