Results 1 to 4 of 4
Thread: Help with components layout
- 01-24-2012, 08:10 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 27
- Rep Power
- 0
Help with components layout
Hi ppl;
I have a problem how the applet is opening, every component are in strange psositions, any help please?
Java Code:import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.ListSelectionModel; public class teste extends JFrame implements ActionListener { private JTextField t1; private JLabel l1, l2, l3, l4; private JPanel p1,p2,p3,p4, p5; private JRadioButton rb1, rb2; private JCheckBox cb1,cb2,cb3; private ButtonGroup grupo; private JTextArea ta1; private JButton bt1, bt2; public void init() { setLayout(new GridLayout(5,2)); //1º linha p1 = new JPanel(); p1.setLayout(new GridLayout(1,2)); l1 = new JLabel("Nome"); t1 = new JTextField(10); p1.add(l1); p1.add(t1); //2ª linha p2 = new JPanel(); p2.setLayout(new GridLayout(1,2)); l2 = new JLabel("Género"); rb1 = new JRadioButton("Maculino"); rb1.addActionListener(this); rb2 = new JRadioButton("Feminino"); rb2.addActionListener(this); p2.add(l2); p2.add(rb1); p2.add(rb2); ButtonGroup grupo=new ButtonGroup(); grupo.add(rb1); grupo.add(rb2); //3ª linha p3 = new JPanel(); p3.setLayout(new GridLayout(1,2)); l3 = new JLabel("Passatempos"); cb1 = new JCheckBox("Ler"); cb2 = new JCheckBox("Jogar"); cb3 = new JCheckBox("Viajar"); p3.add(l3); p3.add(cb1); p3.add(cb2); p3.add(cb3); //4ª Linha p4 = new JPanel(); p4.setLayout(new GridLayout(1,2)); l4 = new JLabel("Morada"); ta1 = new JTextArea(5,20); p4.add(l4); p4.add(ta1); //5ª linha p5 = new JPanel(); p5.setLayout(new GridLayout(1,2)); bt1 = new JButton("Limpar"); bt1.addActionListener(this); bt2 = new JButton("Ver +"); bt2.addActionListener(this); p5.add(bt1); p5.add(bt2); //Componentes na applet add(p1); add(p2); add(p3); add(p4); add(p5); } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub } }
Thanks
- 01-24-2012, 08:32 PM #2
Re: Help with components layout
What Applet?
They will be where the layout managers you use place them. Have you gone through Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing) ?every component are in strange psositions
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-24-2012, 09:27 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 27
- Rep Power
- 0
Re: Help with components layout
Sorry, instead of JFrame is JApplet.
But i have already saw that site but can't put all together and organized.
I want to have 5 rows and 2 columns and each cell has one component.
any help to resolve this issue?
regards
- 01-25-2012, 05:19 AM #4
Re: Help with components layout
5 rows and 2 columns sounds like a GridLayout(5, 2) -- which you already have, but the components you are adding to this layout are panels each with its own GridLayout(1, 2) -- which will give you 4 components across.
Just reading may not be enough; you need to actually do the exercises in the layout tutorial trail.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
layout struts 2 forms components vertically
By saleh_neu in forum Web FrameworksReplies: 1Last Post: 01-12-2011, 09:30 AM -
Help needed in layout of components
By silversurfer2in in forum AWT / SwingReplies: 2Last Post: 05-27-2010, 11:50 AM -
Components Layout in a JPanel
By jboy in forum New To JavaReplies: 4Last Post: 10-11-2009, 12:08 PM -
Layout problem / add components from another class
By ehochedez in forum AWT / SwingReplies: 9Last Post: 09-02-2009, 10:42 AM -
Inconsistent layout w/dynamic resize of components
By donb2000 in forum AWT / SwingReplies: 3Last Post: 07-26-2008, 02:40 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks