I created this code in java to train a little and learn but I can not set where JComboBox
and JTextField
will appear and the size of them like I do? I want to leave them in the middle of the window without being glued to the edge of the window and to each other and not taking the entire window. setSize
and setBounds
are not working.
Code:
/*Biblioteca */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
class creator {
public static void main(String args[]){
/*Gera os campos, tela, e configurações */
JFrame frame = new JFrame();
JPanel panel = new JPanel(new BorderLayout());
JTextField texto = new JTextField();
JComboBox combo = new JComboBox();
/*Cria as opções e configurações do JComboBox */
combo.setBackground(Color.WHITE);
combo.addItem("opção1");
combo.addItem("opção2");
combo.addItem("opção3");
/*Adiciona as coisas na tela */
panel.add(texto);
panel.add(combo);
/*Configurações da janela*/
frame.setSize(500, 500);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
}