Olá, galerinha do GUJ!
Tudo bem?
Estava fazendo uma interface e usando GlazedLists, e me ocorreu um pequeno problema.
Bom, eu tenho uma View aqui:
private class WinPrincipal extends JFrame
{
private transient SortedList<Object> anClientes;
private transient EventComboBoxModel<Object> anComboBoxModel;
private transient JMenuBar anMenuBar;
private transient JLabel anLabel;
private transient JComboBox anComboClientes;
private transient JPanel anConteudoPanel, anClientePanel, anButtonsPanel,
anUsuarioLogadoPanel;
private transient JButton anButtonClientes, anButtonUsuarios, anButtonTiposPlanos,
anButtonDocumentos, anButtonTiposDocumentos, anButtonLocalizacoes;
public WinPrincipal()
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MigLayout anLayout = new MigLayout("nogrid, fillx");
setLayout(anLayout);
anConteudoPanel = new JPanel(anLayout);
anConteudoPanel.add( createMenuBar(), "dock north, width 100%" );
anConteudoPanel.add( createClientePanel(), "width 100%, wrap" ); //<---------------
anConteudoPanel.add( createButtonsPanel(), "width 100%, height 85%" );
anConteudoPanel.add( createPanelUsuarioLogado(), "dock south, width 100%" );
setContentPane(anConteudoPanel);
}
catch (Exception anError)
{
anError.printStackTrace();
}
}
}
E beleza… Ela faz uma chamada ao método abaixo:
private JPanel createClientePanel()
{
anClientePanel = new JPanel( new MigLayout("", "push[][]push") );
anLabel = new JLabel("Escolha o cliente para acessar:");
anClientePanel.add(anLabel);
anClientePanel.add(createClientesComboBox(), "width 30%"); //<--------------
return anClientePanel;
}
private JComboBox createClientesComboBox()
{
if (anComboClientes == null) anComboClientes = new JComboBox();
Collection<Object> anCollection = new ArrayList<Object>();
anCollection.add("João");
anCollection.add("Pedro");
anCollection.add("Luciano");
atualizarListaClientes(anCollection); //<-------------------
return anComboClientes;
}
// Aqui é que está o problema!
private void atualizarListaClientes(Collection<Object> anCollection)
{
anClientes = new SortedList<Object>(GlazedLists.eventList(anCollection));
anComboBoxModel = new EventComboBoxModel<Object>(anClientes);
anComboClientes.setModel(anComboBoxModel);
AutoCompleteSupport.install(anComboClientes, anClientes);
}
Vamos lá… Qual é o problema?
Quando eu faço a chamada do AutoCompleteSupport, no método atualizarListaClientes, me dá a seguinte Exception:
java.lang.IllegalStateException: AutoCompleteSupport must be accessed from the Swing Event Dispatch Thread, but was called on Thread "main"
at ca.odell.glazedlists.swing.AutoCompleteSupport.checkAccessThread(AutoCompleteSupport.java:514)
at ca.odell.glazedlists.swing.AutoCompleteSupport.install(AutoCompleteSupport.java:814)
at ca.odell.glazedlists.swing.AutoCompleteSupport.install(AutoCompleteSupport.java:755)
at ca.odell.glazedlists.swing.AutoCompleteSupport.install(AutoCompleteSupport.java:719)
Eu não estou chamando no Main, como podem ver. Não dá pra criar uma thread ali dentro, pois ele pede pra criar variáveis constantes, mas meus valores serão mutáveis, então fica fora de questão.
Alguma ideia de como resolver isso?
Valeu, abraços!