como se certificar se um usuario escolheu um dado em jcombobox??
em um jtextfild e relativamente simples (verifico se ele tá vazio)
Crie uma opção com o valor vazio, depois é só validar se a opção escolhida é diferente de vazio.
Exemplificando o que eu falei
package com.rge.imobiliaria;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class TestesLog4J extends JFrame{
JComboBox comboBox;
JButton button;
public TestesLog4J() {
comboBox = new JComboBox();
button = new JButton("Validar");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ( ((String)comboBox.getSelectedItem()).equals("") ) {
JOptionPane.showMessageDialog(null, "Nada foi selecionado");
} else {
JOptionPane.showMessageDialog(null, "Foi selecionado " + comboBox.getSelectedItem());
}
}
});
comboBox.addItem("");
comboBox.addItem("opa");
this.setLayout(new FlowLayout());
this.add(comboBox);
this.add(button);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
}
public static void main(String[] args){
new TestesLog4J();
}
}