@SuppressWarnings("serial") public void GegevensTabel(int i) { String[] header = {"Spelernaam", "Pnt", "Res", "Krt"}; String[][] data = null; data = oc.VulTabelRonde(i); spKaarten = new JScrollPane(); getContentPane().add(spKaarten); spKaarten.setBounds(14, 168, 308, 126); spKaarten.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 0, false)); spKaarten.setFont(new java.awt.Font("Arial", 0, 12)); { tKaarten = new JTable(data, header) { public Component prepareRenderer( TableCellRenderer renderer, int rowIndex, int vColIndex) { Component c = super.prepareRenderer(renderer, rowIndex, vColIndex); if (rowIndex % 2 == 0 && !isCellSelected(rowIndex, vColIndex)) { c.setBackground(new java.awt.Color(202, 240, 202)); } else { // If not shaded, match the table's // background c.setBackground(getBackground()); } return c; } }; naamKolom = tKaarten.getColumn(header[0]); naamKolom.setPreferredWidth(150); inzetKolom = tKaarten.getColumn(header[1]); inzetKolom.setPreferredWidth(30); resKolom = tKaarten.getColumn(header[2]); resKolom.setPreferredWidth(50); kaartKolom = tKaarten.getColumn(header[3]); kaartKolom.setPreferredWidth(30); spKaarten.setViewportView(tKaarten); tKaarten.setPreferredSize(new java.awt.Dimension(301, 126)); tKaarten.setGridColor(new java.awt.Color(255, 255, 255)); tKaarten.setBorder(new LineBorder(new java.awt.Color(90, 90, 90), 1, false)); FlowLayout tKaartenLayout = new FlowLayout(); tKaartenLayout.setAlignment(FlowLayout.LEFT); tKaarten.setLayout(tKaartenLayout); tKaarten.setFont(new java.awt.Font("Tahoma", 0, 12)); } } // public void GegevensTabel(int i)
private void setColumnWidths(int[] sizes) { TableColumnModel tcm = table.getColumnModel(); for (int i = 0; i < table.getColumnCount(); i++) { TableColumn tc = tcm.getColumn(i); int maxw = ((sizes == null) || (i >= sizes.length)) ? 10 : sizes[i]; // model.getPreferredWidthForColumn(tc) : sizes[i]; tc.setPreferredWidth(maxw); } // table.sizeColumnsToFit(0); // must be called due to a JTable bug }
@Override public void updateUI() { // Bug ID: 6788475 Changing to Nimbus LAF and back doesn't reset look and feel of JTable // completely // http://bugs.java.com/view_bug.do?bug_id=6788475 // XXX: set dummy ColorUIResource setSelectionForeground(new ColorUIResource(Color.RED)); setSelectionBackground(new ColorUIResource(Color.RED)); super.updateUI(); putClientProperty("Table.isFileList", Boolean.TRUE); setCellSelectionEnabled(true); setIntercellSpacing(new Dimension()); setShowGrid(false); setAutoCreateRowSorter(true); setFillsViewportHeight(true); setDefaultRenderer( Object.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { return super.getTableCellRendererComponent(table, value, false, false, row, column); } }); TableColumn col = getColumnModel().getColumn(0); col.setCellRenderer(new FileNameRenderer(this)); col.setPreferredWidth(200); col = getColumnModel().getColumn(1); col.setPreferredWidth(300); }