Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Problemi con la JTABLE

  1. #1

    Problemi con la JTABLE

    Salve a tutti io ho questo codice e se lo si prova noterete che alle volte quando si clikka su una cella stampa 2 volte lo stesso valore.. PERCHE? sto impazzendo aiuto

    <CODE>
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;

    public class CellSelectionExample implements ListSelectionListener {
    public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable(){
    public void run() {
    new CellSelectionExample().go();
    }
    });
    }

    void go() {
    JFrame f = new JFrame("CellSelectionExample");
    f.getContentPane().add(new JScrollPane(createTable()));
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    }

    JTable createTable() {
    table.setCellSelectionEnabled(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_S ELECTION);
    table.getSelectionModel().addListSelectionListener (this);
    table.getColumnModel().getSelectionModel().addList SelectionListener(this);
    return table;
    }

    @Override()
    public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {
    System.out.format("(%2d,%2d)%n",
    table.getSelectedColumn(), table.getSelectedRow());
    }
    }

    private JTable table = new JTable(20,10);
    }
    </CODE>

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: Problemi con la JTABLE

    Originariamente inviato da Mariolino22
    codice:
            table.getSelectionModel().addListSelectionListener(this);
            table.getColumnModel().getSelectionModel().addListSelectionListener(this);
    Hai registrato 2 volte il tuo listener.
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.