2
I created this code in java to train a little and learn but I can not set the place where the JComboBox
and the JTextField
will appear and the size of them as I do? I want to leave them in the middle of the window without being stuck to the edge of the window and each other and without them grabbing the whole 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);
}
}
Where and how you want to position them?
– user28595
type in the middle of the window with the textfield first above the size combobox that does not catch the whole window.
– Shintaro