valleytech
asked on
GUI issue
hi all,
I use a FlowLayout(). However, i also use setLocation() to place my JCheckBox, Label, Button, Textfield to where i want. I just wonder i am on right track. Thanks.
I use a FlowLayout(). However, i also use setLocation() to place my JCheckBox, Label, Button, Textfield to where i want. I just wonder i am on right track. Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
no you cannot use setLocation() with a FlowLayout. You need to use no (null) layout manager to explicitly set the position.
FlowLayout just put the Component one after the other and center them on a line. I don't remember seeing somewhere that you could change this. You need to use another layout manager that offers control over positioning.
Why do you want to do setLocation? If you post a picture of how you want it to look we could perhaps find another approach
cominations of BorderLayout and BoxLayout will handle most situations.
ASKER
let me search around Borderlayout and boxlayout because i have problem with alignment on flowlayout. i cant control position. Thank you for advises.
Much easier to help if we have a drawing
ASKER
how to post a picture? So i can post my GUI picture. THanks.
You can attach image files directly to this thread
ASKER
i just attach my GUI design. Please take a look at it. Thank you.
GUIdesign.jpg
GUIdesign.jpg
ASKER
the problem i have is i can't control components' locations when using Flowlayout. please advise what kind of lay out i should use. Thanks.
ASKER
I divide it into smaller panels as following:
Printer: MyPrinter,OK as a panel on North
Image,Text,Code, Selection, All, Applet as a panel at Center
Cancel, Setup... as a panel on East
Print Quality, JList, Print to File, Help as a panel on South
I use BorderLayout to add those panels to frame.
Please suggest.
Printer: MyPrinter,OK as a panel on North
Image,Text,Code, Selection, All, Applet as a panel at Center
Cancel, Setup... as a panel on East
Print Quality, JList, Print to File, Help as a panel on South
I use BorderLayout to add those panels to frame.
Please suggest.
close, move OK into East
and break up the centre panel into two (BoxLayout) panels
and break up the centre panel into two (BoxLayout) panels
ASKER
I am coding another one GUI question first because it seems easier. Please take a look at it too :)
let me start coding this.
let me start coding this.
Wouldn't it be a lot easier just to use an ide's gui designer? e.g. Netbeans?
ASKER
well, i try to learn how to manually code GUI . I have moved from netbeans to eclipse :)
>>well, i try to learn how to manually code GUI .
Well that's good practise if you have the time ;-)
Well that's good practise if you have the time ;-)
ASKER
once i know how to do it manually, I can use netbeans to generate GUI code and reuse it on eclipse to make my life easier. So i must know this stuff.
ASKER
so far i have completed this , but not really like i want about the space between JCheckBox, and All radiobutton location !!!! please help
========
import java.awt.BorderLayout;
import java.awt.GridBagConstraint s;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class Printer extends JFrame {
private JLabel MyPrinterJLabel;
private JCheckBox ImageJCheckBox;
private JCheckBox TextJCheckBox;
private JCheckBox CodeJCheckBox;
private JRadioButton SelectionJRadioButton ;
private JRadioButton AllJRadioButton;
private JRadioButton AppletJRadioButton;
private JLabel QualityJLabel;
private JList OptionJList;
private JCheckBox PrintJCheckBox;
private JButton OKJButton;
private JButton CancelJButton;
private JButton SetupJButton;
private JButton HelpJButton;
private JPanel NorthJPanel, EastJPanel, SouthJPanel, CenterJPanel;
public Printer()
{
super("Printer");
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.setBorder(Bord erFactory. createEmpt yBorder(5, 5,10,10));
this.setContentPane(conten tPane);
MyPrinterJLabel= new JLabel("Printer:MyPrinter" );
NorthJPanel = new JPanel();
NorthJPanel.add(MyPrinterJ Label);
this.setLayout(new BorderLayout());
this.add(NorthJPanel,Borde rLayout.NO RTH);
ImageJCheckBox= new JCheckBox("Image");
TextJCheckBox = new JCheckBox("Text");
CodeJCheckBox = new JCheckBox("Code");
SelectionJRadioButton = new JRadioButton("Selection");
AllJRadioButton = new JRadioButton("All");
AppletJRadioButton = new JRadioButton("Applet");
CenterJPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
Insets leftInsets = new Insets (10,10,10,10);
Insets rightInsets = new Insets(10,10,10,10);
gbc.gridx =0;
gbc.gridy=0;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(ImageJChe ckBox,gbc) ;
gbc.gridx =1;
gbc.gridy=0;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(Selection JRadioButt on,gbc);
gbc.gridx =0;
gbc.gridy=1;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(TextJChec kBox,gbc);
gbc.gridx =1;
gbc.gridy=1;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(AllJRadio Button,gbc );
gbc.gridx =0;
gbc.gridy=3;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(CodeJChec kBox,gbc);
gbc.gridx =1;
gbc.gridy=3;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(AppletJRa dioButton, gbc);
OKJButton = new JButton("OK");
CancelJButton = new JButton("Cancel");
SetupJButton = new JButton("Setup...");
HelpJButton = new JButton("Help");
EastJPanel = new JPanel(new GridLayout(4,1,5,5));
EastJPanel.add(OKJButton);
EastJPanel.add(CancelJButt on);
EastJPanel.add(SetupJButto n);
EastJPanel.add(HelpJButton );
this.add(CenterJPanel, BorderLayout.CENTER);
this.add(EastJPanel, BorderLayout.EAST);
/*
import javax.swing.JFrame;
public class MainClass {
public static void main(String[] args) {
Printer PrinterInstance = new Printer();
PrinterInstance.setDefault CloseOpera tion(JFram e.EXIT_ON_ CLOSE);
PrinterInstance.setSize(47 0,200);
PrinterInstance.setLocatio nRelativeT o(null);
PrinterInstance.setVisible (true);
}
}
*/
}
}
1.jpg
========
import java.awt.BorderLayout;
import java.awt.GridBagConstraint
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class Printer extends JFrame {
private JLabel MyPrinterJLabel;
private JCheckBox ImageJCheckBox;
private JCheckBox TextJCheckBox;
private JCheckBox CodeJCheckBox;
private JRadioButton SelectionJRadioButton ;
private JRadioButton AllJRadioButton;
private JRadioButton AppletJRadioButton;
private JLabel QualityJLabel;
private JList OptionJList;
private JCheckBox PrintJCheckBox;
private JButton OKJButton;
private JButton CancelJButton;
private JButton SetupJButton;
private JButton HelpJButton;
private JPanel NorthJPanel, EastJPanel, SouthJPanel, CenterJPanel;
public Printer()
{
super("Printer");
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.setBorder(Bord
this.setContentPane(conten
MyPrinterJLabel= new JLabel("Printer:MyPrinter"
NorthJPanel = new JPanel();
NorthJPanel.add(MyPrinterJ
this.setLayout(new BorderLayout());
this.add(NorthJPanel,Borde
ImageJCheckBox= new JCheckBox("Image");
TextJCheckBox = new JCheckBox("Text");
CodeJCheckBox = new JCheckBox("Code");
SelectionJRadioButton = new JRadioButton("Selection");
AllJRadioButton = new JRadioButton("All");
AppletJRadioButton = new JRadioButton("Applet");
CenterJPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
Insets leftInsets = new Insets (10,10,10,10);
Insets rightInsets = new Insets(10,10,10,10);
gbc.gridx =0;
gbc.gridy=0;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(ImageJChe
gbc.gridx =1;
gbc.gridy=0;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(Selection
gbc.gridx =0;
gbc.gridy=1;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(TextJChec
gbc.gridx =1;
gbc.gridy=1;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(AllJRadio
gbc.gridx =0;
gbc.gridy=3;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(CodeJChec
gbc.gridx =1;
gbc.gridy=3;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(AppletJRa
OKJButton = new JButton("OK");
CancelJButton = new JButton("Cancel");
SetupJButton = new JButton("Setup...");
HelpJButton = new JButton("Help");
EastJPanel = new JPanel(new GridLayout(4,1,5,5));
EastJPanel.add(OKJButton);
EastJPanel.add(CancelJButt
EastJPanel.add(SetupJButto
EastJPanel.add(HelpJButton
this.add(CenterJPanel, BorderLayout.CENTER);
this.add(EastJPanel, BorderLayout.EAST);
/*
import javax.swing.JFrame;
public class MainClass {
public static void main(String[] args) {
Printer PrinterInstance = new Printer();
PrinterInstance.setDefault
PrinterInstance.setSize(47
PrinterInstance.setLocatio
PrinterInstance.setVisible
}
}
*/
}
}
1.jpg
> well, i try to learn how to manually code GUI
we find that to be a better approach. We find our students that have relied on gui builders really struggle.
A BoxLayout can be easier to handle alignment than a GridBagLayout
And use a GridLayout to better split the two columns
we find that to be a better approach. We find our students that have relied on gui builders really struggle.
A BoxLayout can be easier to handle alignment than a GridBagLayout
And use a GridLayout to better split the two columns
ASKER
could you explain in more details?
I have problem because the checkbox, radiobutton, and cancel button are on same line :)
I have problem because the checkbox, radiobutton, and cancel button are on same line :)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
__geof__ earlier suggestion about using SpringLaypout is also worth looking into. Its a nice flexible layout manager.
ASKER
I have problem because the checkbox, radiobutton, and cancel button are on same line <-- -i means at centerpanel we have 3 rows vs cancel + setup are 2 rows.
That's why i can't just use gridbaglayout.
That's why i can't just use gridbaglayout.
I actually never use GBL, never found a layout that couldn't be done without it
ASKER
I actually never use GBL, never found a layout that couldn't be done without it <-- u never use it !!! then u claim no layout couldn't be done without it!!!
I see conflict here objects :)
I see conflict here objects :)
ASKER
hello all experts......
any progress?
ASKER
well i do some research recently about eclipse vs netbeans. I find out that myeclipse can handle GUI within eclipse. so I gonna restart this task again :).
ASKER
i don't know why it can't display on the first row. Please show me my error. Thanks.
====
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridBagConstraint s;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class Printer extends JFrame {
private JLabel MyPrinterJLabel;
private JCheckBox ImageJCheckBox;
private JCheckBox TextJCheckBox;
private JCheckBox CodeJCheckBox;
private JRadioButton SelectionJRadioButton ;
private JRadioButton AllJRadioButton;
private JRadioButton AppletJRadioButton;
private JLabel QualityJLabel;
private JList OptionJList;
private JCheckBox PrintJCheckBox;
private JButton OKJButton;
private JButton CancelJButton;
private JButton SetupJButton;
private JButton HelpJButton;
private JPanel NorthJPanel, EastJPanel, SouthJPanel, CenterJPanel;
public Printer()
{
super("Printer");
Container pane = this.getContentPane();
pane.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
MyPrinterJLabel= new JLabel("Printer:MyPrinter" );
gbc.fill = GridBagConstraints.HORIZON TAL;
gbc.gridx = 0;
gbc.gridy=0;
pane.add(MyPrinterJLabel,g bc);
OKJButton = new JButton("OK");
gbc.fill = GridBagConstraints.HORIZON TAL;
gbc.gridx =1;
gbc.gridy =0;
gbc.insets = new Insets(0,270,0,0);
pane.add(OKJButton,gbc);
}
}
====
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridBagConstraint
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class Printer extends JFrame {
private JLabel MyPrinterJLabel;
private JCheckBox ImageJCheckBox;
private JCheckBox TextJCheckBox;
private JCheckBox CodeJCheckBox;
private JRadioButton SelectionJRadioButton ;
private JRadioButton AllJRadioButton;
private JRadioButton AppletJRadioButton;
private JLabel QualityJLabel;
private JList OptionJList;
private JCheckBox PrintJCheckBox;
private JButton OKJButton;
private JButton CancelJButton;
private JButton SetupJButton;
private JButton HelpJButton;
private JPanel NorthJPanel, EastJPanel, SouthJPanel, CenterJPanel;
public Printer()
{
super("Printer");
Container pane = this.getContentPane();
pane.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
MyPrinterJLabel= new JLabel("Printer:MyPrinter"
gbc.fill = GridBagConstraints.HORIZON
gbc.gridx = 0;
gbc.gridy=0;
pane.add(MyPrinterJLabel,g
OKJButton = new JButton("OK");
gbc.fill = GridBagConstraints.HORIZON
gbc.gridx =1;
gbc.gridy =0;
gbc.insets = new Insets(0,270,0,0);
pane.add(OKJButton,gbc);
}
}
Not quite sure what you see as your problem..?
ASKER
i want to have the Printer:MyPrinter and OK button should be on the first row. How can i display in the middle of the frame?
use a BorderLayout
ASKER
so for the first row, i should use BorderLayout. Am I right?
yes, North panel of BorderLayout is good for puutting a row across the top
ASKER
Let me implement this idea immediately :)
ASKER
done first row. What should I do next :)?
====
public Printer()
{
super("Printer");
//Container pane = this.getContentPane();
//pane.setLayout(new GridBagLayout());
layout = new BorderLayout();
setLayout(layout);
GridBagConstraints gbc = new GridBagConstraints();
NorthJPanel = new JPanel (new GridBagLayout());
MyPrinterJLabel= new JLabel("Printer:MyPrinter" );
gbc.fill = GridBagConstraints.HORIZON TAL;
gbc.gridx = 0;
gbc.gridy=0;
NorthJPanel.add(MyPrinterJ Label,gbc) ;
OKJButton = new JButton("OK");
gbc.fill = GridBagConstraints.HORIZON TAL;
gbc.gridx =1;
gbc.gridy =0;
gbc.insets = new Insets(0,270,0,0);
NorthJPanel.add(OKJButton, gbc);
add(NorthJPanel,BorderLayo ut.NORTH);
}
====
public Printer()
{
super("Printer");
//Container pane = this.getContentPane();
//pane.setLayout(new GridBagLayout());
layout = new BorderLayout();
setLayout(layout);
GridBagConstraints gbc = new GridBagConstraints();
NorthJPanel = new JPanel (new GridBagLayout());
MyPrinterJLabel= new JLabel("Printer:MyPrinter"
gbc.fill = GridBagConstraints.HORIZON
gbc.gridx = 0;
gbc.gridy=0;
NorthJPanel.add(MyPrinterJ
OKJButton = new JButton("OK");
gbc.fill = GridBagConstraints.HORIZON
gbc.gridx =1;
gbc.gridy =0;
gbc.insets = new Insets(0,270,0,0);
NorthJPanel.add(OKJButton,
add(NorthJPanel,BorderLayo
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i see. please advise what i need to do next. Thanks.
>>i see. please advise what i need to do next.
Well i don't know what you want to do
Well i don't know what you want to do
ASKER
oh i want to create same GUI that i scanned.
add your buttons in the EAST
and create a panel for your checkboxes and add that center
and create a panel for your checkboxes and add that center
ASKER
ok. let me implement it now.
ASKER
I lost control of Cancel and Setup buttons. Please help.
========================== ========== ========== ========== =====
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridBagConstraint s;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class Printer extends JFrame {
private JLabel MyPrinterJLabel;
private JCheckBox ImageJCheckBox;
private JCheckBox TextJCheckBox;
private JCheckBox CodeJCheckBox;
private JRadioButton SelectionJRadioButton ;
private JRadioButton AllJRadioButton;
private JRadioButton AppletJRadioButton;
private JLabel QualityJLabel;
private JList OptionJList;
private JCheckBox PrintJCheckBox;
private JButton OKJButton;
private JButton CancelJButton;
private JButton SetupJButton;
private JButton HelpJButton;
private JPanel NorthJPanel, EastJPanel, SouthJPanel, CenterJPanel;
private BorderLayout layout;
public Printer()
{
super("Printer");
//Container pane = this.getContentPane();
//pane.setLayout(new GridBagLayout());
layout = new BorderLayout();
// setLayout(layout);
getContentPane().setLayout (layout);
GridBagConstraints gbc = new GridBagConstraints();
NorthJPanel = new JPanel (new GridBagLayout());
MyPrinterJLabel= new JLabel("Printer:MyPrinter" );
gbc.fill = GridBagConstraints.HORIZON TAL;
gbc.gridx = 0;
gbc.gridy=0;
NorthJPanel.add(MyPrinterJ Label,gbc) ;
OKJButton = new JButton("OK");
gbc.fill = GridBagConstraints.HORIZON TAL;
gbc.gridx =1;
gbc.gridy =0;
gbc.insets = new Insets(0,270,0,0);
NorthJPanel.add(OKJButton, gbc);
add(NorthJPanel,BorderLayo ut.NORTH);
CancelJButton = new JButton("Cancel");
SetupJButton = new JButton ("Setup...");
EastJPanel = new JPanel(new GridLayout(2,1,5,5));
EastJPanel.add(CancelJButt on);
EastJPanel.add(SetupJButto n);
add(EastJPanel,BorderLayou t.EAST);
ImageJCheckBox= new JCheckBox("Image");
TextJCheckBox = new JCheckBox("Text");
CodeJCheckBox = new JCheckBox("Code");
SelectionJRadioButton = new JRadioButton("Selection");
AllJRadioButton = new JRadioButton("All");
AppletJRadioButton = new JRadioButton("Applet");
CenterJPanel = new JPanel(new GridBagLayout());
Insets leftInsets = new Insets (10,10,10,10);
Insets rightInsets = new Insets(10,10,10,10);
gbc.gridx =0;
gbc.gridy=0;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(ImageJChe ckBox,gbc) ;
gbc.gridx =1;
gbc.gridy=0;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(Selection JRadioButt on,gbc);
gbc.gridx =0;
gbc.gridy=1;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(TextJChec kBox,gbc);
gbc.gridx =1;
gbc.gridy=1;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(AllJRadio Button,gbc );
gbc.gridx =0;
gbc.gridy=3;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(CodeJChec kBox,gbc);
gbc.gridx =1;
gbc.gridy=3;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(AppletJRa dioButton, gbc);
add(CenterJPanel,BorderLay out.CENTER );
}
}
==========================
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridBagConstraint
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class Printer extends JFrame {
private JLabel MyPrinterJLabel;
private JCheckBox ImageJCheckBox;
private JCheckBox TextJCheckBox;
private JCheckBox CodeJCheckBox;
private JRadioButton SelectionJRadioButton ;
private JRadioButton AllJRadioButton;
private JRadioButton AppletJRadioButton;
private JLabel QualityJLabel;
private JList OptionJList;
private JCheckBox PrintJCheckBox;
private JButton OKJButton;
private JButton CancelJButton;
private JButton SetupJButton;
private JButton HelpJButton;
private JPanel NorthJPanel, EastJPanel, SouthJPanel, CenterJPanel;
private BorderLayout layout;
public Printer()
{
super("Printer");
//Container pane = this.getContentPane();
//pane.setLayout(new GridBagLayout());
layout = new BorderLayout();
// setLayout(layout);
getContentPane().setLayout
GridBagConstraints gbc = new GridBagConstraints();
NorthJPanel = new JPanel (new GridBagLayout());
MyPrinterJLabel= new JLabel("Printer:MyPrinter"
gbc.fill = GridBagConstraints.HORIZON
gbc.gridx = 0;
gbc.gridy=0;
NorthJPanel.add(MyPrinterJ
OKJButton = new JButton("OK");
gbc.fill = GridBagConstraints.HORIZON
gbc.gridx =1;
gbc.gridy =0;
gbc.insets = new Insets(0,270,0,0);
NorthJPanel.add(OKJButton,
add(NorthJPanel,BorderLayo
CancelJButton = new JButton("Cancel");
SetupJButton = new JButton ("Setup...");
EastJPanel = new JPanel(new GridLayout(2,1,5,5));
EastJPanel.add(CancelJButt
EastJPanel.add(SetupJButto
add(EastJPanel,BorderLayou
ImageJCheckBox= new JCheckBox("Image");
TextJCheckBox = new JCheckBox("Text");
CodeJCheckBox = new JCheckBox("Code");
SelectionJRadioButton = new JRadioButton("Selection");
AllJRadioButton = new JRadioButton("All");
AppletJRadioButton = new JRadioButton("Applet");
CenterJPanel = new JPanel(new GridBagLayout());
Insets leftInsets = new Insets (10,10,10,10);
Insets rightInsets = new Insets(10,10,10,10);
gbc.gridx =0;
gbc.gridy=0;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(ImageJChe
gbc.gridx =1;
gbc.gridy=0;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(Selection
gbc.gridx =0;
gbc.gridy=1;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(TextJChec
gbc.gridx =1;
gbc.gridy=1;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(AllJRadio
gbc.gridx =0;
gbc.gridy=3;
gbc.insets= leftInsets;
gbc.anchor = GridBagConstraints.WEST;
CenterJPanel.add(CodeJChec
gbc.gridx =1;
gbc.gridy=3;
gbc.insets= rightInsets;
gbc.anchor = GridBagConstraints.EAST;
CenterJPanel.add(AppletJRa
add(CenterJPanel,BorderLay
}
}
why use GBL, a simple BoxLayout should suffice
ASKER
oh i thought GBL help to lay out components in appropriate location. let me change.
ASKER
after i changed to Boxlayout, i can't make it work. please help.
=================
public Printer()
{
super("Printer");
//Container pane = this.getContentPane();
//pane.setLayout(new GridBagLayout());
layout = new BorderLayout();
setLayout(layout);
GridBagConstraints gbc = new GridBagConstraints();
NorthJPanel = new JPanel (new GridBagLayout());
MyPrinterJLabel= new JLabel("Printer:MyPrinter" );
gbc.fill = GridBagConstraints.HORIZON TAL;
gbc.gridx = 0;
gbc.gridy=0;
NorthJPanel.add(MyPrinterJ Label,gbc) ;
OKJButton = new JButton("OK");
gbc.fill = GridBagConstraints.HORIZON TAL;
gbc.gridx =1;
gbc.gridy =0;
gbc.insets = new Insets(0,270,0,0);
NorthJPanel.add(OKJButton, gbc);
add(NorthJPanel,BorderLayo ut.NORTH);
/*
CancelJButton = new JButton("Cancel");
SetupJButton = new JButton ("Setup...");
EastJPanel = new JPanel(new GridLayout(2,1,5,5));
EastJPanel.add(CancelJButt on);
EastJPanel.add(SetupJButto n);
add(EastJPanel,BorderLayou t.EAST);
*/
ImageJCheckBox= new JCheckBox("Image");
TextJCheckBox = new JCheckBox("Text");
CodeJCheckBox = new JCheckBox("Code");
SelectionJRadioButton = new JRadioButton("Selection");
AllJRadioButton = new JRadioButton("All");
AppletJRadioButton = new JRadioButton("Applet");
Box horizontalBox = Box.createHorizontalBox();
horizontalBox.add(ImageJCh eckBox );
horizontalBox.add(TextJChe ckBox);
horizontalBox.add(CodeJChe ckBox);
horizontalBox.add(Selectio nJRadioBut ton);
horizontalBox.add(AllJRadi oButton);
horizontalBox.add(AppletJR adioButton );
add(horizontalBox,BorderLa yout.CENTE R);
}
=================
public Printer()
{
super("Printer");
//Container pane = this.getContentPane();
//pane.setLayout(new GridBagLayout());
layout = new BorderLayout();
setLayout(layout);
GridBagConstraints gbc = new GridBagConstraints();
NorthJPanel = new JPanel (new GridBagLayout());
MyPrinterJLabel= new JLabel("Printer:MyPrinter"
gbc.fill = GridBagConstraints.HORIZON
gbc.gridx = 0;
gbc.gridy=0;
NorthJPanel.add(MyPrinterJ
OKJButton = new JButton("OK");
gbc.fill = GridBagConstraints.HORIZON
gbc.gridx =1;
gbc.gridy =0;
gbc.insets = new Insets(0,270,0,0);
NorthJPanel.add(OKJButton,
add(NorthJPanel,BorderLayo
/*
CancelJButton = new JButton("Cancel");
SetupJButton = new JButton ("Setup...");
EastJPanel = new JPanel(new GridLayout(2,1,5,5));
EastJPanel.add(CancelJButt
EastJPanel.add(SetupJButto
add(EastJPanel,BorderLayou
*/
ImageJCheckBox= new JCheckBox("Image");
TextJCheckBox = new JCheckBox("Text");
CodeJCheckBox = new JCheckBox("Code");
SelectionJRadioButton = new JRadioButton("Selection");
AllJRadioButton = new JRadioButton("All");
AppletJRadioButton = new JRadioButton("Applet");
Box horizontalBox = Box.createHorizontalBox();
horizontalBox.add(ImageJCh
horizontalBox.add(TextJChe
horizontalBox.add(CodeJChe
horizontalBox.add(Selectio
horizontalBox.add(AllJRadi
horizontalBox.add(AppletJR
add(horizontalBox,BorderLa
}
:-)
ASKER