// This handles the row, column, and cell selection buttons. public void actionPerformed(ActionEvent ie) { // See which button is selected. if (jrbRows.isSelected()) { // Enable row selection. jtabOrders.setColumnSelectionAllowed(false); jtabOrders.setRowSelectionAllowed(true); } else if (jrbColumns.isSelected()) { // Enable column selection. jtabOrders.setColumnSelectionAllowed(true); jtabOrders.setRowSelectionAllowed(false); } else { // Enable cell selection. jtabOrders.setCellSelectionEnabled(true); } }
@SuppressWarnings("unused") private void jbInit() throws Exception { for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) data[i][j] = new Integer(i * 10 + j); System.out.println("Header length=" + header[1]); jTable1 = new JTable(data, header); jTable1.setCellSelectionEnabled(true); this.setTitle("Excel Lent JTABLE"); jTable1.setBackground(Color.pink); this.setLayout(borderLayout1); this.setSize(new Dimension(400, 300)); this.setBackground(Color.white); JScrollPane scrollPane = new JScrollPane(jTable1); this.add(scrollPane, BorderLayout.CENTER); // This is the line that does all the magic! ExcelAdapter myAd = new ExcelAdapter(jTable1); }
private void loadView() { // main views mTableModel = new SpreadsheetTableModel(); mTableView = new JTable(mTableModel); mTableView.setRowSelectionAllowed(false); mTableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); mTableView.setFillsViewportHeight(true); mTableView.setDefaultRenderer(String.class, new ColorCellRenderer(TABLE_CELL_COLOR)); mTableView.setDefaultEditor( String.class, new SpreadsheetCellEditor(mTableView.getDefaultEditor(String.class))); mTableView.getSelectionModel().addListSelectionListener(new SpreadsheetSelectionListener()); mTableView .getColumnModel() .getSelectionModel() .addListSelectionListener(new SpreadsheetSelectionListener()); JTable rowHeaderTable = new JTable(new RowHeaderTableModel()); rowHeaderTable.setCellSelectionEnabled(false); rowHeaderTable.setPreferredScrollableViewportSize(new Dimension(50, Integer.MAX_VALUE)); rowHeaderTable.setDefaultRenderer(Object.class, new ColorCellRenderer(ROW_HEADER_COLOR)); mFormulaTextField = new BindableTextField(); mFormulaTextField.setEditable(false); mFormulaTextField.setFocusable(false); JScrollPane scrollView = new JScrollPane(mTableView); scrollView.setRowHeaderView(rowHeaderTable); add(mFormulaTextField, BorderLayout.BEFORE_FIRST_LINE); add(scrollView, BorderLayout.CENTER); // helpers mFileChooser = new SingleExtensionFileChooser(); String extension = SpreadsheetPersistenceManager.SPREADSHEET_FILE_EXTENSION; mFileChooser.setFileExtension(extension, "Spreadsheets file (." + extension + ")"); }
private void jbInit() throws Exception { panel1.setLayout(borderLayout1); okButton.setText("OK"); okButton.addActionListener(new MimeTypeEditor_okButton_actionAdapter(this)); filtersTable.setRowSelectionAllowed(true); filtersTable.setPreferredSize(new Dimension(418, 200)); filtersTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); filtersTable.setCellSelectionEnabled(true); filtersTable.setColumnSelectionAllowed(false); filtersTable.setModel(m_model); addButton.setToolTipText( "Add a new " + mimeTypeEditorBuilder.getValueName() + " for a MIME type"); addButton.setText("Add"); addButton.addActionListener(new MimeTypeEditor_addButton_actionAdapter(this)); cancelButton.setText("Cancel"); cancelButton.addActionListener(new MimeTypeEditor_cancelButton_actionAdapter(this)); deleteButton.setToolTipText("Delete the currently selected item."); deleteButton.setText("Delete"); deleteButton.addActionListener(new MimeTypeEditor_deleteButton_actionAdapter(this)); upButton.setText("Up"); upButton.addActionListener(new MimeTypeEditor_upButton_actionAdapter(this)); dnButton.setText("Down"); dnButton.addActionListener(new MimeTypeEditor_dnButton_actionAdapter(this)); panel1.setPreferredSize(new Dimension(418, 200)); jScrollPane1.setMinimumSize(new Dimension(200, 80)); jScrollPane1.setOpaque(true); buttonPanel.add(dnButton, null); buttonPanel.add(upButton, null); buttonPanel.add(addButton, null); buttonPanel.add(deleteButton, null); buttonPanel.add(okButton, null); buttonPanel.add(cancelButton, null); getContentPane().add(panel1); panel1.add(buttonPanel, BorderLayout.SOUTH); panel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.getViewport().add(filtersTable, null); }
public Viajes() { super.setBounds(181, 61, 700, 538); // (ancho,alto) super.setLayout(null); super.setOpaque(false); super.setVisible(false); try { UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (Exception ex) { ex.printStackTrace(); } tbDatos = new JTable(dataModel); tbDatos.setEnabled(false); tbDatos.setAutoResizeMode(5); tbDatos.setCellSelectionEnabled(true); tbDatos.setForeground(Color.BLACK); pnDatos = new JScrollPane(tbDatos); pnDatos.setBounds(30, 30, 640, 478); pnDatos.setVisible(false); this.add(pnDatos); llenarDatos(); jlbCodigo = new JLabel("*Código"); jlbCodigo.setBounds(90, 100, 220, 25); jlbCodigo.setForeground(Color.BLACK); jlbCodigo.setFont(new Font("Segoe UI", Font.PLAIN, 18)); this.add(jlbCodigo); jtxtCodigo = new JTextField(""); jtxtCodigo.setBounds(90, 125, 520, 30); jtxtCodigo.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); jtxtCodigo.addKeyListener(this); this.add(jtxtCodigo); jlbOrigen = new JLabel("*Origen"); jlbOrigen.setBounds(90, 180, 150, 25); jlbOrigen.setForeground(Color.BLACK); jlbOrigen.setFont(new Font("Segoe UI", Font.PLAIN, 18)); this.add(jlbOrigen); jcbOrigen = new JComboBox(); jcbOrigen.setBorder(null); jcbOrigen.setBackground(Color.WHITE); jcbOrigen.addItem("Medellín"); jcbOrigen.addItem("Bogotá"); jcbOrigen.addItem("Barranquilla"); jcbOrigen.setBounds(90, 205, 250, 30); this.add(jcbOrigen); jlbDestino = new JLabel("*Destino"); jlbDestino.setBounds(360, 180, 150, 25); jlbDestino.setForeground(Color.BLACK); jlbDestino.setFont(new Font("Segoe UI", Font.PLAIN, 18)); this.add(jlbDestino); jcbDestino = new JComboBox(); jcbDestino.setBorder(null); jcbDestino.setBackground(Color.WHITE); jcbDestino.addItem("Bogotá"); jcbDestino.addItem("Medellín"); jcbDestino.addItem("Barranquilla"); jcbDestino.setBounds(360, 205, 250, 30); this.add(jcbDestino); jlbPrecio = new JLabel("*Precio"); jlbPrecio.setBounds(90, 260, 120, 25); jlbPrecio.setForeground(Color.BLACK); jlbPrecio.setFont(new Font("Segoe UI", Font.PLAIN, 18)); this.add(jlbPrecio); jtxtPrecio = new JTextField(""); jtxtPrecio.setBounds(90, 285, 520, 30); jtxtPrecio.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); jtxtPrecio.addKeyListener(this); this.add(jtxtPrecio); jlbEstado = new JLabel("*Estado"); jlbEstado.setBounds(90, 340, 150, 25); jlbEstado.setForeground(Color.BLACK); jlbEstado.setFont(new Font("Segoe UI", Font.PLAIN, 18)); this.add(jlbEstado); jcbEstado = new JComboBox(); jcbEstado.setBorder(null); jcbEstado.setBackground(Color.WHITE); jcbEstado.addItem("Activo"); jcbEstado.addItem("Inactivo"); jcbEstado.setBounds(90, 365, 520, 30); this.add(jcbEstado); jbtnListar = new JButton(" Lista"); jbtnListar.setBounds(0, 0, 233, 60); jbtnListar.setIcon(new ImageIcon(getClass().getResource("/Imagenes/icons/List-26.png"))); jbtnListar.setBorder(null); jbtnListar.setBackground(new Color(0, 154, 225)); jbtnListar.setForeground(Color.WHITE); jbtnListar.setFont(new Font("Segoe UI", Font.PLAIN, 20)); jbtnListar.setCursor(new Cursor(java.awt.Cursor.HAND_CURSOR)); jbtnListar.addMouseListener(this); jbtnListar.addActionListener(this); jbtnListar.setFocusPainted(false); this.add(jbtnListar); jbtnBuscar = new JButton(" Buscar"); jbtnBuscar.setBounds(233, 0, 234, 60); jbtnBuscar.setIcon(new ImageIcon(getClass().getResource("/Imagenes/icons/Search-26.png"))); jbtnBuscar.setBorder(null); jbtnBuscar.setBackground(new Color(0, 154, 225)); jbtnBuscar.setForeground(Color.WHITE); jbtnBuscar.setFont(new Font("Segoe UI", Font.PLAIN, 20)); jbtnBuscar.setCursor(new Cursor(java.awt.Cursor.HAND_CURSOR)); jbtnBuscar.addMouseListener(this); jbtnBuscar.addActionListener(this); jbtnBuscar.setFocusPainted(false); this.add(jbtnBuscar); jbtnActualizar = new JButton(" Actualizar"); jbtnActualizar.setBounds(233, 0, 234, 60); jbtnActualizar.setIcon(new ImageIcon(getClass().getResource("/Imagenes/icons/Edit-26.png"))); jbtnActualizar.setBorder(null); jbtnActualizar.setBackground(new Color(0, 154, 225)); jbtnActualizar.setForeground(Color.WHITE); jbtnActualizar.setFont(new Font("Segoe UI", Font.PLAIN, 20)); jbtnActualizar.setCursor(new Cursor(java.awt.Cursor.HAND_CURSOR)); jbtnActualizar.addMouseListener(this); jbtnActualizar.setVisible(false); jbtnActualizar.addActionListener(this); jbtnActualizar.setFocusPainted(false); this.add(jbtnActualizar); jbtnLimpiar = new JButton(" Limpiar"); jbtnLimpiar.setBounds(467, 0, 233, 60); jbtnLimpiar.setIcon(new ImageIcon(getClass().getResource("/Imagenes/icons/Clean-26.png"))); jbtnLimpiar.setBorder(null); jbtnLimpiar.setBackground(new Color(0, 154, 225)); jbtnLimpiar.setForeground(Color.WHITE); jbtnLimpiar.setFont(new Font("Segoe UI", Font.PLAIN, 20)); jbtnLimpiar.setCursor(new Cursor(java.awt.Cursor.HAND_CURSOR)); jbtnLimpiar.addMouseListener(this); jbtnLimpiar.addActionListener(this); jbtnLimpiar.setFocusPainted(false); this.add(jbtnLimpiar); jpBotones = new JPanel(); jpBotones.setBackground(new Color(0, 123, 183)); jpBotones.add(jbtnListar); jpBotones.add(jbtnBuscar); jpBotones.add(jbtnActualizar); jpBotones.add(jbtnLimpiar); jpBotones.setLayout(null); jpBotones.setBounds(0, 478, 700, 60); this.add(jpBotones); jlbValidar = new JLabel("Los campos con (*) son obligatorios"); jlbValidar.setForeground(Color.WHITE); jlbValidar.setBounds(80, 8, 300, 27); jlbValidar.setFont(new Font("Segoe UI", Font.PLAIN, 17)); this.add(jlbValidar); jpError = new JPanel(); jpError.add(jlbValidar); jpError.setLayout(null); jpError.setBackground(new Color(0, 123, 183)); jpError.setBounds(0, 0, 700, 45); this.add(jpError); this.repaint(); }
public MemoryPanel(final Debugger debugger, boolean is64Bit) { super(); this.debugger = debugger; this.is64Bit = is64Bit; if (is64Bit) { addressSize = 8; unmappedAddrString = "??????????????????"; } else { addressSize = 4; unmappedAddrString = "??????????"; } setLayout(new BorderLayout()); setupScrollBar(); add(scrollBar, BorderLayout.EAST); model = new AbstractTableModel() { public int getRowCount() { return numVisibleRows; } public int getColumnCount() { return 2; } public Object getValueAt(int row, int column) { switch (column) { case 0: return bigIntToHexString( startVal.add(new BigInteger(Integer.toString((row * addressSize))))); case 1: { try { Address addr = bigIntToAddress( startVal.add(new BigInteger(Integer.toString((row * addressSize))))); if (addr != null) { return addressToString(addr.getAddressAt(0)); } return unmappedAddrString; } catch (UnmappedAddressException e) { return unmappedAddrString; } } default: throw new RuntimeException("Column " + column + " out of bounds"); } } public boolean isCellEditable(int row, int col) { return false; } }; // View with JTable with no header table = new JTable(model); table.setTableHeader(null); table.setShowGrid(false); table.setIntercellSpacing(new Dimension(0, 0)); table.setCellSelectionEnabled(true); table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setDragEnabled(true); Font font = GraphicsUtilities.lookupFont("Courier"); if (font == null) { throw new RuntimeException("Error looking up monospace font Courier"); } table.setFont(font); // Export proper data. // We need to keep our own notion of the selection in order to // properly export data, since the selection can go beyond the // visible area on the screen (and since the table's model doesn't // back all of those slots). // Code thanks to Shannon.Hickey@sfbay table.setTransferHandler( new TransferHandler() { protected Transferable createTransferable(JComponent c) { JTable table = (JTable) c; if (haveSelection()) { StringBuffer buf = new StringBuffer(); int iDir = (getRowAnchor() < getRowLead() ? 1 : -1); int jDir = (getColAnchor() < getColLead() ? 1 : -1); for (int i = getRowAnchor(); i != getRowLead() + iDir; i += iDir) { for (int j = getColAnchor(); j != getColLead() + jDir; j += jDir) { Object val = model.getValueAt(i, j); buf.append(val == null ? "" : val.toString()); if (j != getColLead()) { buf.append("\t"); } } if (i != getRowLead()) { buf.append("\n"); } } return new StringTransferable(buf.toString()); } return null; } public int getSourceActions(JComponent c) { return COPY; } public boolean importData(JComponent c, Transferable t) { if (canImport(c, t.getTransferDataFlavors())) { try { String str = (String) t.getTransferData(DataFlavor.stringFlavor); handleImport(c, str); return true; } catch (UnsupportedFlavorException ufe) { } catch (IOException ioe) { } } return false; } public boolean canImport(JComponent c, DataFlavor[] flavors) { for (int i = 0; i < flavors.length; i++) { if (DataFlavor.stringFlavor.equals(flavors[i])) { return true; } } return false; } private void handleImport(JComponent c, String str) { // do whatever you want with the string here try { makeVisible(debugger.parseAddress(str)); clearSelection(); table.clearSelection(); } catch (NumberFormatException e) { System.err.println("Unable to parse address \"" + str + "\""); } } }); // Supporting keyboard scrolling // See src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java, // search for Table.AncestorInputMap // Actions to override: // selectPreviousRow, selectNextRow, // scrollUpChangeSelection, scrollDownChangeSelection, // selectPreviousRowExtendSelection, selectNextRowExtendSelection, // scrollDownExtendSelection, scrollUpExtendSelection (Shift-PgDn/PgUp) ActionMap map = table.getActionMap(); // Up arrow installActionWrapper( map, "selectPreviousRow", new ActionWrapper() { public void actionPerformed(ActionEvent e) { beginUpdate(); clearSelection(); if (table.getSelectedRow() == 0) { scrollBar.scrollUpOrLeft(); table.setRowSelectionInterval(0, 0); } else { super.actionPerformed(e); } maybeGrabSelection(); endUpdate(); } }); // Down arrow installActionWrapper( map, "selectNextRow", new ActionWrapper() { public void actionPerformed(ActionEvent e) { beginUpdate(); clearSelection(); int row = table.getSelectedRow(); if (row >= numUsableRows) { scrollBar.scrollDownOrRight(); table.setRowSelectionInterval(row, row); } else { super.actionPerformed(e); } maybeGrabSelection(); endUpdate(); } }); // Page up installActionWrapper( map, "scrollUpChangeSelection", new ActionWrapper() { public void actionPerformed(ActionEvent e) { beginUpdate(); clearSelection(); int row = table.getSelectedRow(); scrollBar.pageUpOrLeft(); if (row >= 0) { table.setRowSelectionInterval(row, row); } maybeGrabSelection(); endUpdate(); } }); // Page down installActionWrapper( map, "scrollDownChangeSelection", new ActionWrapper() { public void actionPerformed(ActionEvent e) { beginUpdate(); clearSelection(); int row = table.getSelectedRow(); scrollBar.pageDownOrRight(); if (row >= 0) { table.setRowSelectionInterval(row, row); } maybeGrabSelection(); endUpdate(); } }); // Shift + Up arrow installActionWrapper( map, "selectPreviousRowExtendSelection", new ActionWrapper() { public void actionPerformed(ActionEvent e) { beginUpdate(); if (!haveAnchor()) { setAnchorFromTable(); setLeadFromTable(); // setAnchor(table.getSelectedRow()); // setLead(table.getSelectedRow()); } int newLead = getRowLead() - 1; int newAnchor = getRowAnchor(); if (newLead < 0) { scrollBar.scrollUpOrLeft(); ++newLead; ++newAnchor; } setSelection(newAnchor, newLead, getColAnchor(), getColLead()); // printSelection(); endUpdate(); } }); // Shift + Left arrow installActionWrapper( map, "selectPreviousColumnExtendSelection", new ActionWrapper() { public void actionPerformed(ActionEvent e) { beginUpdate(); if (!haveAnchor()) { setAnchorFromTable(); setLeadFromTable(); } int newLead = Math.max(0, getColLead() - 1); setSelection(getRowAnchor(), getRowLead(), getColAnchor(), newLead); // printSelection(); endUpdate(); } }); // Shift + Down arrow installActionWrapper( map, "selectNextRowExtendSelection", new ActionWrapper() { public void actionPerformed(ActionEvent e) { beginUpdate(); if (!haveAnchor()) { setAnchorFromTable(); setLeadFromTable(); // setAnchor(table.getSelectedRow()); // setLead(table.getSelectedRow()); } int newLead = getRowLead() + 1; int newAnchor = getRowAnchor(); if (newLead > numUsableRows) { scrollBar.scrollDownOrRight(); --newLead; --newAnchor; } setSelection(newAnchor, newLead, getColAnchor(), getColLead()); // printSelection(); endUpdate(); } }); // Shift + Right arrow installActionWrapper( map, "selectNextColumnExtendSelection", new ActionWrapper() { public void actionPerformed(ActionEvent e) { beginUpdate(); if (!haveAnchor()) { setAnchorFromTable(); setLeadFromTable(); } int newLead = Math.min(model.getColumnCount() - 1, getColLead() + 1); setSelection(getRowAnchor(), getRowLead(), getColAnchor(), newLead); // printSelection(); endUpdate(); } }); // Shift + Page up installActionWrapper( map, "scrollUpExtendSelection", new ActionWrapper() { public void actionPerformed(ActionEvent e) { beginUpdate(); if (!haveAnchor()) { setAnchorFromTable(); setLeadFromTable(); // setAnchor(table.getSelectedRow()); // setLead(table.getSelectedRow()); } int newLead = getRowLead() - numUsableRows; int newAnchor = getRowAnchor(); if (newLead < 0) { scrollBar.pageUpOrLeft(); newLead += numUsableRows; newAnchor += numUsableRows; } setSelection(newAnchor, newLead, getColAnchor(), getColLead()); // printSelection(); endUpdate(); } }); // Shift + Page down installActionWrapper( map, "scrollDownExtendSelection", new ActionWrapper() { public void actionPerformed(ActionEvent e) { beginUpdate(); if (!haveAnchor()) { setAnchorFromTable(); setLeadFromTable(); // setAnchor(table.getSelectedRow()); // setLead(table.getSelectedRow()); } int newLead = getRowLead() + numUsableRows; int newAnchor = getRowAnchor(); if (newLead > numUsableRows) { scrollBar.pageDownOrRight(); newLead -= numUsableRows; newAnchor -= numUsableRows; } setSelection(newAnchor, newLead, getColAnchor(), getColLead()); // printSelection(); endUpdate(); } }); // Clear our notion of selection upon mouse press table.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { if (shouldIgnore(e)) { return; } // Make shift-clicking work properly if (e.isShiftDown()) { maybeGrabSelection(); return; } // System.err.println(" Clearing selection on mouse press"); clearSelection(); } }); // Watch for mouse going out of bounds table.addMouseMotionListener( new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { if (shouldIgnore(e)) { // System.err.println(" (Ignoring consumed mouse event)"); return; } // Look for drag events outside table and scroll if necessary Point p = e.getPoint(); if (table.rowAtPoint(p) == -1) { // See whether we are above or below the table Rectangle rect = new Rectangle(); getBounds(rect); beginUpdate(); if (p.y < rect.y) { // System.err.println(" Scrolling up due to mouse event"); // Scroll up scrollBar.scrollUpOrLeft(); setSelection(getRowAnchor(), 0, getColAnchor(), getColLead()); } else { // System.err.println(" Scrolling down due to mouse event"); // Scroll down scrollBar.scrollDownOrRight(); setSelection(getRowAnchor(), numUsableRows, getColAnchor(), getColLead()); } // printSelection(); endUpdate(); } else { maybeGrabSelection(); } } }); add(table, BorderLayout.CENTER); // Make sure we recompute number of visible rows addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent e) { recomputeNumVisibleRows(); constrain(); } }); addHierarchyListener( new HierarchyListener() { public void hierarchyChanged(HierarchyEvent e) { recomputeNumVisibleRows(); constrain(); } }); updateFromScrollBar(); }