this is rarely a recommended solution, but might suit
http://java.sun.com/docs/books/tutorial/uiswing/layout/none.html
but using a null layout usually produces other problems.
to consider a layoutManager would require more info
e.g.
where's label2 and textbox go? upper right?
what's beneath label1/label2? space? other components?
how big is the frame?
are the textboxes the same width as the labels?
are the labels the same width?
etc
etc
much easier if you post a sample program, so we can see exactly what you have,
then tell us how you want it all to appear.
Is this good enough?
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;
import java.text.DecimalFormat;
public class Start
{
DecimalFormat df;
JFrame f1;
JTextField Pieces,FDTt,FDTw,FDTl;
JButton Calculate, Finish, Cancel, Add;
JPanel p1,p2,p3,p4,p5,p6,p7,p8;
JLabel piece, fd, rd, m, a, b, sf, t, tc,Disclaimer,cost,BDFT,FCost;
Container c1;
String RtS,RwS,RlS,pS,Selected,selection,totals,ans4;
double Supply=1.35;
double Tax=1.065;
double T,W,L,A,B,C,BDFTL,Total,p;
int remember,xx=0;
double c=0;
double d=0;
double ans3=0;
double ans=0;
double ans2=0;
int No=0;
String[] names;
ArrayList woodlist,Receipt;
String [] type = {"Plywood","Lumber","-"};
JComboBox Type = new JComboBox(type);
JLabel HEY;
Start st;
Project P;
String material;
public Start(double To)
{
restofconstruct();
}
public Start(ArrayList wd, double To)
{
woodlist = new ArrayList();
woodlist = wd;
Receipt= new ArrayList();
restofconstruct();
Total=To;
}
public Start(ArrayList wd, double To, ArrayList rcpt)
{
woodlist = new ArrayList();
woodlist = wd;
Receipt=new ArrayList();
Receipt=rcpt;
Total=To;
restofconstruct();
}
public void restofconstruct()
{
df = new DecimalFormat("0.##");
HEY = new JLabel();
JPanel content = new JPanel();//new GridLayout(2,1)//);
content.add(new JLabel(" No. of Pieces"));
content.setBackground(Color.white);
p3= new JPanel();
p3.setBackground(Color.white);
content.add(p3);
Pieces = new JTextField(2);
Pieces.setText("0");
p3.add(Pieces);
JPanel contentfd = new JPanel();//new GridLayout(2,1));
contentfd.add(new JLabel(" Finished Dimensions"));
contentfd.setBackground(Color.white);
p2=new JPanel();
p2.setBackground(Color.white);
contentfd.add(p2);
FDTt= new JTextField(3);
FDTt.setText("0");
FDTw= new JTextField(3);
FDTw.setText("0");
FDTl= new JTextField(3);
FDTl.setText("0");
p2.add(FDTt);
p2.add(FDTw);
p2.add(FDTl);
JPanel contentm = new JPanel();//new GridLayout(2,1));
contentm.add(new JLabel("Kind of Material"));
contentm.setBackground(Color.white);
p4 = new JPanel();
p4.setBackground(Color.white);
//ComboBox
names = new String[woodlist.size()+1];
for (int x = 0;x<woodlist.size();x++)
{
names[x]=((Wood)(woodlist.get(x))).getName();
xx=x;
}
names[xx+1]="-";
JComboBox Woods = new JComboBox(names);
Woods.setSelectedIndex(woodlist.size()-0);
Woods.addActionListener(new MenuListener());
Type.setSelectedIndex(2);
Type.addActionListener(new WoodListener());
p4.add(Type);
//End of ComboBox
p4.add(Woods);
contentm.add(p4);
JPanel contentbdft = new JPanel();//new GridLayout(2,1));
contentbdft.add(new JLabel("BD FT./ SQ. FT."));
contentbdft.setBackground(Color.white);
BDFT = new JLabel("");
contentbdft.add(BDFT);
contentbdft.add(new JLabel("Cost/Foot"));
cost=new JLabel("");
contentbdft.add(cost);
contentbdft.add(new JLabel("Cost"));
FCost = new JLabel("");
contentbdft.add(FCost);
JPanel Buttons = new JPanel();//new GridLayout(3,1));
Buttons.setBackground(Color.white);
Buttons.add(HEY);
Finish = new JButton(" Finish ");
Finish.addActionListener(new ButtonListener());
Cancel = new JButton(" Cancel ");
Cancel.addActionListener(new ButtonListener());
Add = new JButton(" Add Another Piece");
Add.addActionListener(new ButtonListener());
Buttons.add(Add);
Buttons.add(new JLabel(""));
Buttons.add(new JLabel(""));
Buttons.add(Finish);
Buttons.add(new JLabel(" "));
Buttons.add(new JLabel(""));
Buttons.add(Cancel);
JPanel Final = new JPanel();
Final.setBackground(Color.white);
Final.add(new JLabel("Supply Factor x $1.35"));
Final.add(new JLabel(""));
Final.add(new JLabel("Taxx 6.5%"));
Final.add(new JLabel(""));
Final.add(new JLabel("Final Total$"+FCost));
f1 = new JFrame(" Bill of Materials & Stock Cutting List ");
f1.setSize(831,650);
f1.addKeyListener(new UpdateListener());
p1 = new JPanel();
p1.setBackground(Color.white);
c1 = f1.getContentPane();
p1.add(content);
p1.add(contentfd);
p1.add(contentm);
p1.add(contentbdft);
p1.add(new JLabel(" "));
p1.add(Buttons);
p1.add(HEY);
c1.add(p1);
f1.show();
}
public void calculate (double c)
{
c=c;
pS= Pieces.getText();
p=Double.parseDouble(pS);
if (FDTt==null )
T=0;
else
{
RtS=FDTt.getText();
T=Double.parseDouble(RtS);
}
if (FDTw==null)
W=0;
else
{
RwS=FDTw.getText();
W=Double.parseDouble(RwS);
}
if (FDTl==null)
L=0;
else
{
RlS=FDTl.getText();
L=Double.parseDouble(RlS);
}
if (Selected.equals("Plywood"))
{
material="Plywood";
RwS=FDTw.getText();
W=Double.parseDouble(RwS);
RlS=FDTl.getText();
L=Double.parseDouble(RlS);
pS=Pieces.getText();
No=Integer.parseInt(pS);
ans = (No * (1+W) *(.5+L))/144;
String ans2=df.format(ans);
BDFT.setText(ans2);
d=1;
}
if (Selected.equals("Lumber"))
{
material ="Lumber";
RtS=FDTt.getText();
T=Double.parseDouble(RtS);
RwS=FDTw.getText();
W=Double.parseDouble(RwS);
RlS=FDTl.getText();
L=Double.parseDouble(RlS);
pS=Pieces.getText();
No=Integer.parseInt(pS);
ans=(No*T*(1+W)*(1+L))/144;
String ans2=df.format(ans);
BDFT.setText(""+ans2);
d=1;
}
if (Selected.equals("-"))
{
BDFT.setText("Please select the kind of wood you'd like to use ");
d=0;
}
ans3=(ans*c);
ans4 = df.format(ans3);
FCost.setText(""+ans4);
}
private class UpdateListener implements KeyListener
{
public void keyPressed(KeyEvent event)
{
calculate(c);
}
public void keyReleased(KeyEvent event)
{}
public void keyTyped(KeyEvent event)
{}
}
private class WoodListener implements ActionListener
{
public void actionPerformed (ActionEvent select)
{
JComboBox twood = (JComboBox)select.getSource();
Selected = (String)twood.getSelectedItem();
calculate(c);
}
}
private class MenuListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
JComboBox cb = (JComboBox)event.getSource();
selection = (String)cb.getSelectedItem();
remember=-1;
for (int x = 0;x<woodlist.size();x++)
{
if (selection.equals(((Wood)woodlist.get(x)).getName()))
remember=x;
}
if (remember==-1)
c=0;
else
{
Wood w =(Wood)(woodlist.get(remember));
c= w.getCost();
}
if (c==0)
{
c=0;
cost.setText("Please select the material you'd like to use ");
}
else
cost.setText(""+c);
calculate(c);
}
}
private class ButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
if (event.getSource()== Finish)
{
Total=Total+ans3;
RtS=FDTt.getText();
T=Double.parseDouble(RtS);
RwS=FDTw.getText();
W=Double.parseDouble(RwS);
RlS=FDTl.getText();
L=Double.parseDouble(RlS);
pS=Pieces.getText();
No=Integer.parseInt(pS);
FDTt.setText("");
FDTw.setText("");
FDTl.setText("");
Pieces.setText("");
if ((material!=null)||(No!=0))
{
P=new Project(No,T,W,L,material,ans,selection,ans2);
Receipt.add(P);
}
Save_Receipt s = new Save_Receipt(Receipt);
s.save_receipt();
Final_Receipt r = new Final_Receipt(Receipt);
}
if (event.getSource()== Cancel)
{
f1.dispose();
Start_Menu sm = new Start_Menu();
}
if (event.getSource()== Add)
{
if (d==0)
{
HEY.setText("Hey, you don't have a type of wood selected!!");
}
if ((int)c==0)
{
HEY.setText("Hey, you don't have a material selected!!");
}
if ((d==0)&&((int)c==0))
{
HEY.setText("Hey, you don't have a type of wood selected and no material selected!!");
}
if ((d!=0)&&(c!=0))
{
// totals= FCost.getText();
// Total=Double.parseDouble(totals);
Total=Total+ans3;
P=new Project(No,T,W,L,material,ans,selection,ans2);
Receipt.add(P);
// System.out.println(Receipt.get(0));
st = new Start(woodlist,Total,Receipt);
f1.dispose();
}
}
}
}
}
Message was edited by:
ichbinsterben>
> Is this good enough?
No.
1) it doesn't compile - 13 errors - missing class Project etc
2) it is 400 lines long
3) it contains arraylists, decimalformat - what do they have to do with layoutManager problems
here is a *sample program*, related to the description of your problem.
tell us what you want to go where.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing
{
public void buildGUI()
{
JPanel left1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel left2 = new JPanel(new GridLayout(0,1));
JPanel right1 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JPanel right2 = new JPanel(new GridLayout(0,1));
JLabel label1 = new JLabel("Left Side");
JLabel label2 = new JLabel("Right Side",JLabel.RIGHT);
JTextField tf1 = new JTextField(10);
JTextField tf2 = new JTextField(10);
left2.add(label1);
left2.add(tf1);
left1.add(left2);
right2.add(label2);
right2.add(tf2);
right1.add(right2);
JFrame f = new JFrame();
f.getContentPane().add(left1,BorderLayout.WEST);
f.getContentPane().add(right1,BorderLayout.EAST);
f.setSize(400,300);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Testing().buildGUI();
}
});
}
}
Try this:
/** class FourSquareLayout.java*/
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class FourSquareLayout {
private JFrameframe;
private JPanelpanel1,
panel2,
panel3,
panel4;
private JLabellabel1,
label2;
private JTextArea text1,
text2;
private Container container;
public FourSquareLayout() {
frame = new JFrame("FourSquareLayout");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
panel4 = new JPanel();
label1 = new JLabel("JLabel1");
label2 = new JLabel("JLabel2");
text1 = new JTextArea("[Textbox]",10,10);
text2 = new JTextArea("[Textbox]",10,10);
container= frame.getContentPane();
panel1.setLayout(new FlowLayout(FlowLayout.LEFT));
panel2.setLayout(new FlowLayout(FlowLayout.RIGHT));
panel3.setLayout(new BorderLayout());
panel4.setLayout(new BorderLayout());
container.setLayout(new GridLayout(1, 2, 10, 10));
panel1.add(label1);
panel2.add(label2);
panel3.add(panel1, BorderLayout.NORTH);
panel3.add(text1, BorderLayout.CENTER);
panel4.add(panel2, BorderLayout.NORTH);
panel4.add(text2, BorderLayout.CENTER);
container.add(panel3);
container.add(panel4);
frame.pack();
frame.setVisible(true);
}
public static void main ( String[] argv ) throws Exception {
new FourSquareLayout();
}
}
The way I'm going for is exactly like a form that you'd fill out online
For Ex
First Name:
Last Name:
Address:
State:
and so on...
Plus it supposed to automatically update when certain things are put in.
so need the Form on the left and the receipt on the right.
Message was edited by:
ichbinsterben