Já tentei de várias formas mas não consigo fazer com que os JLabel, JTextField fiquem alinhados um abaixo do outro, todos ficam um ao lado do outro. Eu gostaria que os JLabels ficassem ao lado do seu respectivo JTextField.
Tenho uma classe principal com os menus:
ApplicationWindow.java
package ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
public class ApplicationWindow extends JFrame
{
private JDesktopPane desktop;
//configura a GUI
public ApplicationWindow()
{
super("titulo"); // titulo
// Declara a barra com os menus
JMenuBar barMenu = new JMenuBar();
setJMenuBar(barMenu);
// Declara os menus
JMenu menuMenu = new JMenu("menu"); // menu
barMenu.add(menuMenu);
// ----------------MENU----------------------------------------------
JMenuItem menuItem = new JMenuItem("Item");
menuMenu.add(menuItem);
//---------------ACOES PARA INSERIR TELAS NA AGENDA--------------------
desktop = new JDesktopPane(); // cria o painel de area de trabalho
desktop.setBackground(Color.lightGray);
this.getContentPane().add(desktop);
// caso o usuario clique em "Inserir Nome"
menuItem.addActionListener(
new ActionListener() // classe interna anonima
{
// exibe a nova janela aberta
public void actionPerformed(ActionEvent evt)
{
// cria o quadro interno
JInternalFrame frame = new JInternalFrame(
"Titulo da janela interna", true, true, true,
true);
// cria uma tela
Container container = frame.getContentPane();
PanelPanel panelPanel =
new PanelPanel();
container.add(panelPanel, BorderLayout.CENTER);
frame.pack();
desktop.add(frame);
frame.setVisible(true);
}
}
);
}
public static void main (String args[])
{
ApplicationWindow application = new ApplicationWindow();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
application.setSize( 800, 600 ); // configura o tamanho do frame
application.setVisible(true); // exibe o frame
}
}
E tenho uma outra classe com o JPanel e suas JLabels e JTextFields
PanelPanel.java
package ui;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class PanelPanel extends JPanel
{
private JLabel lbName;
private JLabel lbSecondName;
private JLabel lbNickName;
private JTextField tfName;
private JTextField tfSecondName;
private JTextField tfNickName;
/**
*
*/
public PanelPanel()
{
// label nome
lbName = new JLabel("Nome: ");
lbName.setLabelFor(tfName);
lbName.setLocation(10, 10);
add(lbName);
// textfield nome
tfName = new JTextField(30);
add(tfName);
// label sobrenome
lbSecondName = new JLabel("Sobrenome: ");
lbSecondName.setLabelFor(tfSecondName);
lbSecondName.setLocation(10, 40);
add(lbSecondName);
// textfield sobrenome
tfSecondName = new JTextField(30);
add(tfSecondName);
// label apelido
lbNickName = new JLabel("Apelido: ");
lbName.setLabelFor(tfNickName);
lbName.setLocation(10, 90);
add(lbNickName);;
// textfield nome
tfNickName= new JTextField(30);
add(tfNickName);
}
}
Só pra constar que eu já tentei com:
lbName.setBounds(int, int, int, int);
Não estou conseguindo posicionar meus JTextFields e JLabels no JPanel
Desde já, obrigado.