I'm creating a program interface where the users selects something into a menu and then it will display several tabs. Inside some tabs there are choices. The problem comes when the user select something from the menu, the tab becomes visible, and the user click menu again, thats what is going on: menu bugged
The code is extense now, so I'm going to stick to the components creation.
Menu item creation:
JMenu menuArquivo = new JMenu("Arquivo");
menuBar.add(menuArquivo);
JMenuItem arqAC = new JMenuItem("Aviso de Cobran\u00E7a");
menuArquivo.add(arqAC);
arqAC.addActionListener(menuItemListener);
arqAC.setActionCommand("AC");
Adding the tabPane to the contentPane:
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
tabs = new ArquivoTabs();
JTabbedPane tabbedPane = tabs.getTabs();
tabbedPane.setBounds(0, 0, 1061, 600);
tabbedPane.setSelectedIndex(index);
contentPane.add(tabbedPane);
tabbedPane.setTitleAt(index, title);
revalidate();
ContentPane:
public ArquivoTabs() {
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
add(tabbedPane);
ACTab act = new ACTab(tabbedPane);
tabbedPane.addTab("AC", null, act, "Aviso de Cobran\u00E7a");
}
One tab creation:
public ACTab(JTabbedPane tp) {
tabbedPane = tp;
aut = Authority.getAuthority();
ButtonListener buttonListener = new ButtonListener();
setLayout(null);
tfAC = new JTextField();
tfAC.setBounds(10, 25, 251, 20);
add(tfAC);
tfAC.setColumns(10);
bpAC = new JButton("Procurar");
bpAC.setBounds(271, 24, 75, 23);
add(bpAC);
bpAC.addActionListener(buttonListener);
bpAC.setActionCommand("bpAC");
JSeparator separator = new JSeparator(JSeparator.HORIZONTAL);
separator.setBounds(10, 68, 336, 9);
add(separator,
BorderLayout.LINE_START);
btnGerarAC = new JButton("GERAR");
btnGerarAC.setBounds(271, 346, 75, 23);
add(btnGerarAC);
btnGerarAC.addActionListener(buttonListener);
btnGerarAC.setActionCommand("btnGerarAC");
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 113, 336, 106);
add(scrollPane);
tfDescDeb = new JTextArea();
scrollPane.setViewportView(tfDescDeb);
tfDescDeb.setFont(new Font("Arial", Font.PLAIN, 14));
tfDescDeb.setColumns(10);
tfDescDeb.setLineWrap(true);
tfDescDeb.setWrapStyleWord(true);
tfDescDeb.setEditable(false);
motTypes = DescDeb.getMotTypes();
choice = new Choice();
choice.setBounds(10, 87, 336, 20);
add(choice);
choice.add("");
for(DescDeb mt : motTypes){
choice.add(mt.getTitle());
}
choice.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent ie)
{
for(DescDeb mt : motTypes){
if(choice.getSelectedItem().equals(mt.getTitle())){
tfDescDeb.setEditable(false);
tfDescDeb.setText(mt.getText());
}
}
}
});
JLabel lblDescDeb = new JLabel("Descri\u00E7\u00E3o dos d\u00E9bitos:");
lblDescDeb.setBounds(10, 73, 110, 14);
add(lblDescDeb);
JLabel lblAutRole = new JLabel("Cargo da Autoridade:");
lblAutRole.setBounds(10, 258, 110, 14);
add(lblAutRole);
txtAutRole = new JTextField();
txtAutRole.setEditable(false);
txtAutRole.setColumns(10);
txtAutRole.setBounds(134, 258, 212, 20);
txtAutRole.setText(aut.getRole());
add(txtAutRole);
JLabel lblAutMat = new JLabel("Matr\u00EDcula da Autoridade:");
lblAutMat.setBounds(10, 286, 118, 14);
add(lblAutMat);
txtAutMat = new JTextField();
txtAutMat.setEditable(false);
txtAutMat.setColumns(10);
txtAutMat.setBounds(134, 286, 212, 20);
txtAutMat.setText(aut.getRegistration());
add(txtAutMat);
JLabel lblAutName = new JLabel("Nome da Autoridade:");
lblAutName.setBounds(10, 230, 102, 14);
add(lblAutName);
txtAutName = new JTextField();
txtAutName.setEditable(false);
txtAutName.setBounds(134, 230, 212, 20);
txtAutName.setText(aut.getName());
add(txtAutName);
JButton btnEditarAutoridade = new JButton("Editar Autoridade");
btnEditarAutoridade.setBounds(226, 317, 119, 23);
btnEditarAutoridade.addActionListener(buttonListener);
btnEditarAutoridade.setActionCommand("edtAut");
add(btnEditarAutoridade);
JLabel lblArquivoDeEntrada = new JLabel("Arquivo de Entrada:");
lblArquivoDeEntrada.setBounds(10, 11, 110, 14);
add(lblArquivoDeEntrada);
}
I have to pass JTabbedPane tp to use it with unrelated stuff.
If more parts of the code are needed, let me know.
You are mixing Swing components (JMenu
, JTabbedPane
) with an AWT component (Choice
). This leads to various problems including the overlap of the Choice
component over the JMenu
.
Use JComboBox
instead of Choice