public SitesPanel(Connection dbConn) { this.dbConn = dbConn; this.setLayout(new BorderLayout()); topPanel.setAlignmentX(CENTER_ALIGNMENT); topPanel.add(siteIDL); topPanel.add(siteIDF); topPanel.add(updateB); updateB.addActionListener(this); sitesTableModel.setColumnIdentifiers( new String[] {"Site ID", "Given Name", "Surname", "Suburb", "State"}); sitesTableModel.addTableModelListener(this); sitesTableListModel.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); sitesTable.setAutoCreateRowSorter(true); tableScroll.setPreferredSize(new Dimension(940, 600)); tablePanel.add(tableScroll); updateSites(); sitesTable .getColumnModel() .getColumn(4) .setCellEditor( new DefaultCellEditor( new JComboBox<String>( new String[] {"", "NSW", "VIC", "QLD", "ACT", "WA", "SA", "TAS", "NT"}))); this.add(topPanel, BorderLayout.NORTH); this.add(tablePanel, BorderLayout.CENTER); }
@SuppressWarnings("static-access") public DeckListComboBoxModel(DefaultListModel<Deck> listModel) { // initialize basics list = listModel; listSelectionModel = new DefaultListSelectionModel(); listSelectionModel.setSelectionMode(listSelectionModel.SINGLE_SELECTION); listSelectionModel.setSelectionInterval(0, 0); // These classes are listeners for data changes @SuppressWarnings("unused") ListSelectionUpdater listSelectionUpdater = new ListSelectionUpdater(); @SuppressWarnings("unused") ListModelUpdater listModelUpdater = new ListModelUpdater(); // Add the contents // updateList(); }
public UIUnidad(IUnidad interfaz) { initComponents(); this.setVisible(true); this.setTitle("MANTENIMIENTO DE UNIDAD"); setLocationRelativeTo(null); this.interfaz = interfaz; interfaz.cargar(tblRegistros); cellSelectionModel = tblRegistros.getSelectionModel(); cellSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); cellSelectionModel.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { interfaz.actualizarEst(tblRegistros, chActivar); } }); interfaz.buscarUnidad(txtBuscar, tblRegistros); }
public String selectTableItem() { printTB.setCellSelectionEnabled(true); ListSelectionModel cellSelectionModel = printTB.getSelectionModel(); cellSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); cellSelectionModel.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int[] selectedRow = printTB.getSelectedRows(); int[] selectedColumns = printTB.getSelectedColumns(); for (int i = 0; i < selectedRow.length; i++) { for (int j = 0; j < selectedColumns.length; j++) { // System.out.println("selectedRow : " + selectedRow[i] + // selectedColumns[0]); save = (String) printTB.getValueAt(selectedRow[i], selectedColumns[j]); } } } }); return save; }
private void initComponents() { setTitle(LanguageBundle.getString("in_companionSelectRace")); // $NON-NLS-1$ setLayout(new BorderLayout()); Container container = getContentPane(); { final ListSelectionModel selectionModel = raceTable.getSelectionModel(); selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); selectionModel.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { selectButton.setEnabled(!selectionModel.isSelectionEmpty()); } } }); } SearchFilterPanel searchBar = new SearchFilterPanel(); container.add(searchBar, BorderLayout.NORTH); raceTable.setDisplayableFilter(searchBar); raceTable.addActionListener(this); raceTable.setTreeViewModel(this); container.add(new JScrollPane(raceTable), BorderLayout.CENTER); JPanel buttonPane = new JPanel(new FlowLayout()); selectButton.addActionListener(this); selectButton.setEnabled(false); selectButton.setActionCommand("SELECT"); buttonPane.add(selectButton); JButton cancelButton = new JButton(LanguageBundle.getString("in_cancel")); cancelButton.addActionListener(this); cancelButton.setActionCommand("CANCEL"); buttonPane.add(cancelButton); container.add(buttonPane, BorderLayout.SOUTH); Utility.installEscapeCloseOperation(this); }
public SimpleTable() { JFrame frame = new JFrame("Table"); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); final String[] names = {"First Name", "Last Name", "Id"}; final Object[][] data = { {"Mark", "Andrews", new Integer(1)}, {"Tom", "Ball", new Integer(2)}, {"Alan", "Chung", new Integer(3)}, }; TableModel dataModel = new AbstractTableModel() { public int getColumnCount() { return names.length; } public int getRowCount() { return data.length; } public Object getValueAt(int row, int col) { return data[row][col]; } public String getColumnName(int column) { return names[column]; } public Class getColumnClass(int col) { return getValueAt(0, col).getClass(); } public void setValueAt(Object aValue, int row, int column) { data[row][column] = aValue; } }; aTable = new JTable(dataModel); ListSelectionModel listMod = aTable.getSelectionModel(); listMod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listMod.addListSelectionListener(this); JScrollPane scrollpane = new JScrollPane(aTable); scrollpane.setPreferredSize(new Dimension(300, 300)); frame.getContentPane().add(scrollpane); frame.pack(); frame.setVisible(true); aTable.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { System.out.println(" double click"); } } }); }
/** * Crea un nuevo panel canal * * @param chatroom */ public ChatRoomPanel(ChatRoom pChatroom) { chatroom = pChatroom; // Creamos la tabla con el modelo de datos proporcionado por // DatosTablaFicheros. usuariosConectados = new JTable(new UsuariosConectadosTableModel(chatroom)); // Guardamos el modelo de los usuarios desconectados para usarlo en el // ActionListener del boton usuariosDesconectadosModel = new UsuariosDesconectadosTableModel(chatroom); // Crreamos la tabla de desconectados usuariosDesconectados = new JTable(usuariosDesconectadosModel); // Establecemos algunos parametros de la tabla, para que solo se pueda // seleccionar 1 fila a la vez ListSelectionModel selectionModel = usuariosConectados.getSelectionModel(); selectionModel.setSelectionInterval(0, 0); selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); selectionModel = usuariosDesconectados.getSelectionModel(); selectionModel.setSelectionInterval(0, 0); selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Añadimos la tabla a un JScroll y lo añadimos a este panel. this.setLayout(new GridLayout(2, 1)); this.add(new JScrollPane(usuariosConectados)); JButton boton = new JButton("Invitar"); boton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int filaSeleccionada = usuariosDesconectados.getSelectedRow(); User usuario = (User) usuariosDesconectadosModel.getValueAt(filaSeleccionada, 0); if (usuario != null) { panchat.invitarUsuario(chatroom, usuario); } } }); // Creamos un JPanel con un GridLayout y añadimos el JComboBox y el // botón JPanel panelBotones = new JPanel(); panelBotones.setLayout(new BorderLayout()); panelBotones.add(new JScrollPane(usuariosDesconectados), BorderLayout.CENTER); panelBotones.add(boton, BorderLayout.SOUTH); this.add(panelBotones); // Configuramos el prefered size como 200 de ancho y máximo de altura this.setPreferredSize(new Dimension(200, Short.MAX_VALUE)); }
private void initComponents() { jbAdd = new JButton( new ImageIcon( Toolkit.getDefaultToolkit() .createImage( getClass().getResource(res.getString("JPolicyInformation.jbAdd.image"))))); jbAdd.setMargin(new Insets(2, 2, 0, 0)); jbAdd.setToolTipText(res.getString("JPolicyInformation.jbAdd.tooltip")); jbAdd.setMnemonic(res.getString("JPolicyInformation.jbAdd.mnemonic").charAt(0)); jbAdd.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { CursorUtil.setCursorBusy(JPolicyInformation.this); addPressed(); } finally { CursorUtil.setCursorFree(JPolicyInformation.this); } } }); jbEdit = new JButton( new ImageIcon( Toolkit.getDefaultToolkit() .createImage( getClass().getResource(res.getString("JPolicyInformation.jbEdit.image"))))); jbEdit.setMargin(new Insets(2, 2, 0, 0)); jbEdit.setToolTipText(res.getString("JPolicyInformation.jbEdit.tooltip")); jbEdit.setMnemonic(res.getString("JPolicyInformation.jbEdit.mnemonic").charAt(0)); jbEdit.setEnabled(false); jbEdit.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { CursorUtil.setCursorBusy(JPolicyInformation.this); editPressed(); } finally { CursorUtil.setCursorFree(JPolicyInformation.this); } } }); jbRemove = new JButton( new ImageIcon( Toolkit.getDefaultToolkit() .createImage( getClass() .getResource(res.getString("JPolicyInformation.jbRemove.image"))))); jbRemove.setMargin(new Insets(2, 2, 0, 0)); jbRemove.setToolTipText(res.getString("JPolicyInformation.jbRemove.tooltip")); jbRemove.setMnemonic(res.getString("JPolicyInformation.jbRemove.mnemonic").charAt(0)); jbRemove.setEnabled(false); jbRemove.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { CursorUtil.setCursorBusy(JPolicyInformation.this); removePressed(); } finally { CursorUtil.setCursorFree(JPolicyInformation.this); } } }); jpPolicyInformationButtons = new JPanel(); jpPolicyInformationButtons.setLayout( new BoxLayout(jpPolicyInformationButtons, BoxLayout.Y_AXIS)); jpPolicyInformationButtons.add(Box.createVerticalGlue()); jpPolicyInformationButtons.add(jbAdd); jpPolicyInformationButtons.add(Box.createVerticalStrut(3)); jpPolicyInformationButtons.add(jbEdit); jpPolicyInformationButtons.add(Box.createVerticalStrut(3)); jpPolicyInformationButtons.add(jbRemove); jpPolicyInformationButtons.add(Box.createVerticalGlue()); PolicyInformationTableModel policyInformationTableModel = new PolicyInformationTableModel(); jtPolicyInformation = new JKseTable(policyInformationTableModel); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(policyInformationTableModel); sorter.setComparator(0, new PolicyInformationTableModel.PolicyInformationComparator()); jtPolicyInformation.setRowSorter(sorter); jtPolicyInformation.setShowGrid(false); jtPolicyInformation.setRowMargin(0); jtPolicyInformation.getColumnModel().setColumnMargin(0); jtPolicyInformation.getTableHeader().setReorderingAllowed(false); jtPolicyInformation.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS); jtPolicyInformation.setRowHeight(Math.max(18, jtPolicyInformation.getRowHeight())); for (int i = 0; i < jtPolicyInformation.getColumnCount(); i++) { TableColumn column = jtPolicyInformation.getColumnModel().getColumn(i); column.setHeaderRenderer( new PolicyInformationTableHeadRend( jtPolicyInformation.getTableHeader().getDefaultRenderer())); column.setCellRenderer(new PolicyInformationTableCellRend()); } ListSelectionModel selectionModel = jtPolicyInformation.getSelectionModel(); selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); selectionModel.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { updateButtonControls(); } } }); jtPolicyInformation.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { maybeEditPolicyInformation(evt); } }); jtPolicyInformation.addKeyListener( new KeyAdapter() { boolean deleteLastPressed = false; @Override public void keyPressed(KeyEvent evt) { // Record delete pressed on non-Macs if (!OperatingSystem.isMacOs()) { deleteLastPressed = evt.getKeyCode() == KeyEvent.VK_DELETE; } } @Override public void keyReleased(KeyEvent evt) { // Delete on non-Mac if delete was pressed and is now released if (!OperatingSystem.isMacOs() && deleteLastPressed && evt.getKeyCode() == KeyEvent.VK_DELETE) { try { CursorUtil.setCursorBusy(JPolicyInformation.this); deleteLastPressed = false; removeSelectedPolicyInformation(); } finally { CursorUtil.setCursorFree(JPolicyInformation.this); } } } @Override public void keyTyped(KeyEvent evt) { // Delete on Mac if back space typed if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) { try { CursorUtil.setCursorBusy(JPolicyInformation.this); removeSelectedPolicyInformation(); } finally { CursorUtil.setCursorFree(JPolicyInformation.this); } } } }); jspPolicyInformation = PlatformUtil.createScrollPane( jtPolicyInformation, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); jspPolicyInformation.getViewport().setBackground(jtPolicyInformation.getBackground()); this.setLayout(new BorderLayout(5, 5)); setPreferredSize(new Dimension(250, 150)); add(jspPolicyInformation, BorderLayout.CENTER); add(jpPolicyInformationButtons, BorderLayout.EAST); populate(); }
MyTableModel(List<Dvd> newData) { data = newData; select = new DefaultListSelectionModel(); select.setSelectionMode(select.SINGLE_INTERVAL_SELECTION); }