<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Últimas mensagens do tópico "Como pegar o item selecionado em um Combo"]]></title>
		<link>http://www.guj.com.br/posts/list/4.java</link>
		<description><![CDATA[Últimas mensagens enviadas no tópico "Como pegar o item selecionado em um Combo"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Como pegar o item selecionado em um Combo</title>
				<description><![CDATA[ Olá,<br /> <br /> Tenho no evento formComponentShown do jFrame o seguinte código:<br />       try {  <br />       TestaConexao conexao = new TestaConexao();<br />       conexao.conectaBanco();<br />       cQuerySql = "select * from ESTADOS order by abreviatura";<br />       resultado_RS = conexao.consultarDados(cQuerySql);<br />       while (resultado_RS.next()) {  <br />           jcb_Estado.addItem(resultado_RS.getString("ABREVIATURA"));<br />       }<br />      } catch(Exception e){<br />         JOptionPane.showMessageDialog(null, "Erro aqui", "Mensagens", JOptionPane.INFORMATION_MESSAGE);<br />         System.out.println(e.getMessage());<br />     }<br /> <br /> Como saber qual o item do combo o usuário selecionou?<br /> ]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/prepost/194795/979324/como-pegar-o-item-selecionado-em-um-combo
</guid>
				<link>http://www.guj.com.br/prepost/194795/979324/como-pegar-o-item-selecionado-em-um-combo
</link>
				<pubDate><![CDATA[Thu, 3 Jul 2008 13:56:16]]> GMT</pubDate>
				<author><![CDATA[ rsa_tchePJ]]></author>
			</item>
			<item>
				<title>Re:Como pegar o item selecionado em um Combo</title>
				<description><![CDATA[ Chama um desses<br /> <br /> [code]<br /> jcb_Estado.getSelectedIndex();<br /> jcb_Estado.getSelectedItem();<br /> [/code]<br /> <br /> Sendo que vc pode usar um ActionListener ou ItemListener para pegar o evento<br /> da seleção.]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/prepost/194795/979330/recomo-pegar-o-item-selecionado-em-um-combo
</guid>
				<link>http://www.guj.com.br/prepost/194795/979330/recomo-pegar-o-item-selecionado-em-um-combo
</link>
				<pubDate><![CDATA[Thu, 3 Jul 2008 18:31:17]]> GMT</pubDate>
				<author><![CDATA[ fabiofalciPJ]]></author>
			</item>
			<item>
				<title>Re:Como pegar o item selecionado em um Combo</title>
				<description><![CDATA[ Olá,<br /> <br /> Eu já tinha usado o  evento itemStateChanged, só que ocorre o seguinte:<br /> Na primeira vez que eu carrego o combo, ou seja, no momento que eu mostro JFrame ocorre o vento  evento itemStateChanged e não se o porque, mas o combo fica somente com um item na lista e não todos os itens. Tenho 3 estados cadastrados (AM, RJ e TO) mas mostra somente o primeiro AM.<br /> Se eu retirar o  evento itemStateChanged, mostra todos.<br /> ]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/prepost/194795/979331/recomo-pegar-o-item-selecionado-em-um-combo
</guid>
				<link>http://www.guj.com.br/prepost/194795/979331/recomo-pegar-o-item-selecionado-em-um-combo
</link>
				<pubDate><![CDATA[Thu, 3 Jul 2008 20:43:32]]> GMT</pubDate>
				<author><![CDATA[ rsa_tchePJ]]></author>
			</item>
			<item>
				<title>Re:Como pegar o item selecionado em um Combo</title>
				<description><![CDATA[ Estranho, não deveria acontecer.<br /> Tenho um exemplinho bem simples, que usa ActionListener e o ItemListener.<br /> Ve se te ajuda.<br /> <br /> [code]<br /> public class ComboTest2 extends JPanel {<br /> <br /> 	JComboBox combo;<br /> <br /> 	public ComboTest2() {<br /> 		this.add(getCombo());<br /> 	}<br /> <br /> 	public JComboBox getCombo() {<br /> 		combo = new JComboBox();<br /> 		combo.addItem(new Bean2("Portal", "Java"));<br /> 		combo.addItem(new Bean2("www", "guj"));<br /> 		combo.addItem(new Bean2("infoq", ".com"));<br /> 		combo.addActionListener(new ActionListener() {<br /> 			@Override<br /> 			public void actionPerformed(ActionEvent e) {<br /> 				System.out.println("ActionListerer " + combo.getSelectedItem());<br /> <br /> 			}<br /> 		});<br /> <br /> 		combo.addItemListener(new ItemListener() {<br /> 			@Override<br /> 			public void itemStateChanged(ItemEvent e) {<br /> 				System.out.println("itemStateChanged " + e.getItem() + " "<br /> 						+ e.getStateChange());<br /> <br /> 			}<br /> 		});<br /> <br /> 		return combo;<br /> 	}<br /> <br /> 	public static void main(String[] args) {<br /> 		JFrame frame = new JFrame();<br /> 		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br /> 		frame.setContentPane(new ComboTest2());<br /> 		frame.setSize(300, 200);<br /> 		frame.setVisible(true);<br /> 	}<br /> }<br /> <br /> class Bean2 {<br /> 	String name;<br /> 	String last;<br /> <br /> 	public Bean2(String name, String last) {<br /> 		this.name = name;<br /> 		this.last = last;<br /> 	}<br /> <br /> 	public String toString() {<br /> 		return name + " " + last;<br /> 	}<br /> }<br /> [/code]]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/prepost/194795/979333/recomo-pegar-o-item-selecionado-em-um-combo
</guid>
				<link>http://www.guj.com.br/prepost/194795/979333/recomo-pegar-o-item-selecionado-em-um-combo
</link>
				<pubDate><![CDATA[Fri, 4 Jul 2008 08:52:55]]> GMT</pubDate>
				<author><![CDATA[ fabiofalciPJ]]></author>
			</item>
	</channel>
</rss>
