1
I created code in java to position objects in the type window JComboBox
and JTextField
and I want them to be below each other. The code I tried is this:
/*Biblioteca */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
class creator {
public static void main(String args[]){
EventQueue.invokeLater(() -> {
/*Cria o layout*/
GridBagLayout layout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
/* Gera os campos, tela, e configurações */
JFrame frame = new JFrame();
JPanel panel = new JPanel(layout);
JTextField texto = new JTextField();
texto.setColumns(15);
JComboBox combo = new JComboBox();
/* Cria as opções e configurações do JComboBox */
combo.setBackground(Color.WHITE);
combo.addItem("op\u00e7\u00e3o1");
combo.addItem("op\u00e7\u00e3o2");
combo.addItem("op\u00e7\u00e3o3");
combo.addItem("op\u00e7\u00e3o4");
combo.addItem("op\u00e7\u00e3o5");
combo.addItem("op\u00e7\u00e3o6");
combo.addItem("op\u00e7\u00e3o7");
/* Adiciona as coisas na tela */
panel.add(texto);
panel.add(combo, c);
/* Configurações da janela */
frame.setTitle("Layout");
frame.setSize(500, 500);
frame.getContentPane().add(panel);
/*seta como o arquivo fecha e sua visibilidade */
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
});
}
}
It’s not the same doubt as the other? -
quero deixar eles no meio da janela sem estarem grudados na borda da janela e um no outro e sem que fiquem pegando a janela inteira
– user28595
no and guy I managed to apply the layout but I could not leave the buttons one below the other and I have researched in thousands of places and ngm explains how it does this.
– Shintaro
How are you not? I made your example rightly basing de la, everything you need to understand this layout has la.
– user28595
I understood only that the buttons don’t stay under each other.
– Shintaro
But it doesn’t mention any of this in the link. It explains how to use this layout.
– user28595
then that’s why I created this topic to know if it is possible using this layout to leave 1 object below the other.
– Shintaro