Solved

help in Layout

Posted on 2000-05-09
11
181 Views
Last Modified: 2010-04-01
hi

I have 2 lists and 2 buttons

----------------------                                    -----------------------

                                         Add
                                       -------->

                                         Del
                                      <--------

----------------------                                    ------------------------

How do I lay them out on screen?

I tried GridLayout overall for Panle and putting the 2 buttons in a sub Panel with BorderLayout.north and south but is not giving nice look

any better suggestion ?

thanks you!
0
Comment
Question by:ShoGun
[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
  • 5
  • 5
11 Comments
 

Author Comment

by:ShoGun
ID: 2794377
code is like this

Panel buttons = new Panel(new BorderLayout());            
            buttons.add(add,BorderLayout.NORTH);
buttons.add(del,BorderLayout.SOUTH);

Panel top = new Panel(new GridLayout(1,3));            top.add(List1);
top.add(buttons);
top.add(List2);
            
add(top);

.....
0
 
LVL 4

Accepted Solution

by:
jerch earned 155 total points
ID: 2795009
0
 
LVL 1

Expert Comment

by:Ik_Khan_Pk
ID: 2795788
//////////////////////////////////
//THE SwingStart PROGRAM.//
//////////////////////////////////

import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.border.*;
public class SwingStart extends Frame {
 public static int WIDTH = 450;
 public static int HEIGHT = 450;
 public static String TITLE = "SwingStart";
 // Swing components
 JTabbedPane tabbedPane = new JTabbedPane();
 JPanel buttonPanel = new JPanel();
 JPanel barPanel = new JPanel();
 JPanel listPanel = new JPanel();
 JPanel tablePanel = new JPanel();
 JPanel[] panels = {buttonPanel,barPanel,listPanel,tablePanel};
 Icon worldIcon = new ImageIcon("world.gif");
 Icon printerIcon = new ImageIcon("printer.gif");
 Icon leaf1Icon = new ImageIcon("leaf1.gif");
 Icon leaf2Icon = new ImageIcon("leaf2.gif");
 Icon leaf3Icon = new ImageIcon("leaf3.gif");
 Icon[] leaves = {leaf1Icon, leaf2Icon, leaf3Icon};
 JButton printerButton = new JButton("Print",printerIcon);
 JToggleButton worldButton = new JToggleButton("Connect",worldIcon,true);
 JList leafList = new JList(leaves);
 JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, 60);
 JProgressBar progressBar = new JProgressBar();
 String[] columns = {"Product ID","Description","Price"};
 Object[][] cells = {columns,{"zvga-1234","Video Card","$50"},
{"56m-11","56K Modem","$315"},
  {"dc-10","Net Card","$499"}};
 JTable table = new JTable(cells,columns);
 {
  super(TITLE);
  addWindowListener(new WindowHandler());
  buildGUI();
  setSize(WIDTH,HEIGHT);
  setBackground(Color.darkGray);
  show();
 }
 
 void buildGUI() {
  // Set up tabbed pane
  String[] tabs = {"Buttons","Bars","Lists","Table"};
  String[] tabTips = {"A Button and a Toggle Button",
   "A Slider and a Progress Bar",
   "An Icon List",
   "A Cost Table"};
  for(int i=0;i<tabs.length;++i) {
   panels[i].setBackground(Color.lightGray);
   panels[i].setBorder(new TitledBorder(tabTips[i]));
   tabbedPane.addTab(tabs[i],null,panels[i],tabTips[i]);
  }
  addComponentsToTabs();
  add("Center",tabbedPane);
 }
 void addComponentsToTabs() {
  setupButtonPanel();
  setupBarPanel();
  setupListPanel();
  setupTablePanel();
}
 void setupButtonPanel() {
  printerButton.setBackground(Color.white);
  worldButton.setBackground(Color.white);
  buttonPanel.add(printerButton);
  buttonPanel.add(worldButton);
 }
 
 void setupBarPanel() {
  slider.setMajorTickSpacing(10);
  slider.setMinorTickSpacing(5);
  slider.setPaintTicks(true);
  slider.addChangeListener(new SliderHandler());
  progressBar.setOrientation(JProgressBar.HORIZONTAL);
  progressBar.setMinimum(0);
  progressBar.setMaximum(100);
  progressBar.setValue(60);
  progressBar.setBorderPainted(true);
  barPanel.add(new JLabel("Slider"));
  barPanel.add(slider);
  barPanel.add(new JLabel("Progress Bar"));
  barPanel.add(progressBar);
}
 
 void setupListPanel() {
  leafList.setFixedCellHeight(123);
  listPanel.add(leafList);
 }
 
 void setupTablePanel() {
  tablePanel.add(table);
 }
 public static void main(String[] args) {
   SwingStart app = new SwingStart();
 }
 public class WindowHandler extends WindowAdapter {
  public void windowClosing(WindowEvent e) {
   System.exit(0);
  }
 }
 public class SliderHandler implements ChangeListener {
  public void stateChanged(ChangeEvent e) {
   progressBar.setValue(slider.getValue());
  }
 }
}
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:ShoGun
ID: 2796423
Adjusted points from 95 to 155
0
 

Author Comment

by:ShoGun
ID: 2796425
Jerson,

I will go with gridBagLayout and thnaks for that!!! it is very teachable ,I will try not to ask you question but can you help me if i need?

Thanks you!
0
 
LVL 4

Expert Comment

by:jerch
ID: 2798403
Sure... no problem... also check this one

http://pandonia.canberra.edu.au/java/xadvisor/gridbag/gridbag.html

best regards...
Jerson
0
 
LVL 4

Expert Comment

by:jerch
ID: 2798436
Sure... no problem... also check this one

http://pandonia.canberra.edu.au/java/xadvisor/gridbag/gridbag.html

best regards...
Jerson
0
 

Author Comment

by:ShoGun
ID: 2805831
thanks i finished that !wow that link is superb
0
 
LVL 4

Expert Comment

by:jerch
ID: 2807673
yeah.. I read it while I was preparing for the SCJP exam. :)

Jerson
0
 

Author Comment

by:ShoGun
ID: 2814320
I printed and raed the whole article and did another layout in guess what ? 25 mins while it took me 2 days to get the first one working nicely.

but did you know that there is a bug for GridBagLayout and it's removed only in latest 2 versions f JDK?

Thanks you!
0
 
LVL 4

Expert Comment

by:jerch
ID: 2815538
:)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

615 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