/** * Default constructor/Create the frame of kick player window * * @param lobby the given lobby associated with the frame * @param table the table the player current on */ public KickPlayerWindow(final ILobby lobby, final Table table) { this.setResizable(false); this.isAlwaysOnTop(); List<Player> playerList = table.getPlayers(); // get to delete the moderator from the list to make sure // the moderator doesn't kick himself playerList.remove(table.getModerator()); playerTable = new JTable(); players = new HashMap<Integer, Player>(); setTitle("Kick player"); setBounds(100, 100, 400, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JScrollPane scrollPane = new JScrollPane(playerTable); scrollPane.setBounds(10, 10, 363, 200); contentPane.add(scrollPane, BorderLayout.CENTER); model = new DefaultTableModel(); model.addColumn("ID"); model.addColumn("Display Name"); model.addColumn("Rating"); playerTable.setModel(model); playerTable.setColumnSelectionAllowed(false); playerTable.setRowSelectionAllowed(true); JTableHeader header = playerTable.getTableHeader(); header.setFont(new Font(header.getFont().getFontName(), Font.BOLD, header.getFont().getSize())); updatePlayers(playerList); JButton btnCancel = new JButton("Cancel"); btnCancel.setBounds(280, 228, 89, 23); contentPane.add(btnCancel); btnCancel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { dispose(); } }); JButton btnKick = new JButton("Kick"); btnKick.setBounds(180, 228, 89, 23); contentPane.add(btnKick); btnKick.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { for (Integer row : playerTable.getSelectedRows()) { Player selected = players.get(model.getValueAt(row, 0)); new LeaveRequest(table, selected).send(lobby); } dispose(); } }); }
/** TableCellRenderer implementation */ public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { // Try to set default fore- and background colors if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); AbstractTableModel model = (AbstractTableModel) table.getModel(); column = table.convertColumnIndexToModel(column); setText(model.getColumnName(column)); // set normal border setBorder(javax.swing.UIManager.getBorder("TableHeader.cellBorder")); if (m_sortmode == SortMode.ASCENDING) setIcon(m_upimage); else if (m_sortmode == SortMode.DESCENDING) setIcon(m_downimage); else // if NONE setIcon(m_emptyheaderimage); } } return this; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); // Inherit the colors and font from the header component if (bookTable_ != null) { JTableHeader header = bookTable_.getTableHeader(); if (header != null) { setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); } } if (value instanceof JLabel) { setIcon(((JLabel) value).getIcon()); setText(((JLabel) value).getText()); } else { setText((value == null) ? "" : value.toString()); setIcon(null); } setBorder(UIManager.getBorder("TableHeader.cellBorder")); setHorizontalAlignment(JLabel.CENTER); return this; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { int index = -1; int direction = 0; if (table != null) { if (table.getModel() instanceof ISorterFilterTableModel) { ISorterFilterTableModel model = (ISorterFilterTableModel) table.getModel(); index = table.convertColumnIndexToView(model.getSortColumn()); direction = model.getSortDirection(); } JTableHeader header = table.getTableHeader(); if (header != null) { setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); } } setIcon( col == index && direction != ISorterFilterTableModel.NONE ? new SortArrowIcon(direction) : null); setText((value == null) ? "" : value.toString()); setBorder(UIManager.getBorder("TableHeader.cellBorder")); return this; }
public HeaderRenderer2(JTableHeader header, final int index) { // index is the column to be modified check.setOpaque(false); check.setFont(header.getFont()); header.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JTable table = ((JTableHeader) e.getSource()).getTable(); TableColumnModel columnModel = table.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int modelColumn = table.convertColumnIndexToModel(viewColumn); if (modelColumn == index) { check.setSelected(!check.isSelected()); TableModel m = table.getModel(); Boolean f = check.isSelected(); for (int i = 0; i < m.getRowCount(); i++) { m.setValueAt(f, i, index); } ((JTableHeader) e.getSource()).repaint(); } else { return; } } }); }
/** * Constructs with the specified initial table * * @param table the instance of JTable */ public RowHeaderTableCellRenderer(JTable table) { header = table.getTableHeader(); setOpaque(true); setBorder(UIManager.getBorder("TableHeader.cellBorder")); // setHorizontalAlignment(CENTER); setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); }
/** Constructor */ public HeaderRenderer(JTable table, boolean rowModel) { this.table = table; this.rowModel = rowModel; JTableHeader header = table.getTableHeader(); this.selectedFont = header.getFont().deriveFont(Font.BOLD); this.unselectedFont = header.getFont(); this.selectedFgColor = UIManager.getColor("textHighlightText"); this.unselectedFgColor = header.getForeground(); this.unselectedBgColor = header.getBackground().darker(); Color c = table.getSelectionBackground(); float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); this.selectedBgColor = Color.getHSBColor(hsb[0], hsb[1] * 2f, hsb[2]); setOpaque(true); setBorder(BorderFactory.createEmptyBorder()); setHorizontalAlignment(CENTER); setForeground(unselectedFgColor); setBackground(unselectedBgColor); setFont(unselectedFont); if (!rowModel) { setBorder( new AbstractBorder() { public Insets getBorderInsets(Component c) { return INSETS; } public Insets getBorderInsets(Component c, Insets insets) { return INSETS; } public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g.setColor(HeaderRenderer.this.table.getGridColor().darker()); g.drawLine(x, y, x + width, y); g.drawLine(x, y, x, y + height); } }); } }
private int preferredHeaderWidth() { JLabel longestRowLabel = new JLabel("65356#"); if (m_width == 1) longestRowLabel = new JLabel("#"); else if (m_width == 2) longestRowLabel = new JLabel("##"); else if (m_width == 3) longestRowLabel = new JLabel("###"); else if (m_width == 4) longestRowLabel = new JLabel("####"); else if (m_width == 5) longestRowLabel = new JLabel("#####"); JTableHeader header = table.getTableHeader(); longestRowLabel.setBorder(header.getBorder()); // UIManager.getBorder("TableHeader.cellBorder")); longestRowLabel.setHorizontalAlignment(JLabel.CENTER); longestRowLabel.setFont(header.getFont()); return longestRowLabel.getPreferredSize().width; }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); header.addMouseListener(this); } } setColumn(column); setBorder(UIManager.getBorder("TableHeader.cellBorder")); return this; }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); } setText(getText(value, row, column)); setBorder(UIManager.getBorder("TableHeader.cellBorder")); setHorizontalAlignment(JLabel.CENTER); } return this; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { setFont(header.getFont()); } } this.isSelected = isSelected; this.hasFocus = hasFocus; this.column = column; this.hasRollover = (column == rolloverColumn); if (skin == null || skin.getContentMargin() == null) { skin = XPStyle.getXP().getSkin(header, "header.headeritem"); } setText((value == null) ? "" : value.toString()); setBorder(new EmptyBorder(skin.getContentMargin())); return this; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); } } if (isSelected) { setFont(getFont().deriveFont(Font.BOLD)); } setText((value == null) ? "" : value.toString()); setBorder(UIManager.getBorder("TableHeader.cellBorder")); return this; }
public ProcessedModulesTable(final Project project) { super(new BorderLayout()); myTableModel = new MyTableModel(project); myTable = new JBTable(myTableModel); myTable.getEmptyText().setText("No modules configured"); // myTable.setShowGrid(false); myTable.setIntercellSpacing(JBUI.emptySize()); myTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); myTable.setColumnSelectionAllowed(false); final TableColumnModel columnModel = myTable.getColumnModel(); final TableColumn dirNameColumn = columnModel.getColumn(myTableModel.DIRNAME_COLUMN_INDEX); final String title = "Generated Sources Directory Name"; dirNameColumn.setHeaderValue(title); final JTableHeader tableHeader = myTable.getTableHeader(); final FontMetrics metrics = tableHeader.getFontMetrics(tableHeader.getFont()); final int preferredWidth = metrics.stringWidth(title) + 12; dirNameColumn.setPreferredWidth(preferredWidth); dirNameColumn.setMaxWidth(preferredWidth + 20); dirNameColumn.setCellRenderer(new MyElementColumnCellRenderer()); final TableColumn moduleColumn = columnModel.getColumn(myTableModel.ELEMENT_COLUMN_INDEX); moduleColumn.setHeaderValue("Module"); moduleColumn.setCellRenderer(new MyElementColumnCellRenderer()); final JPanel panel = ToolbarDecorator.createDecorator(myTable) .disableUpDownActions() .setPreferredSize(JBUI.size(100, 155)) .createPanel(); add(panel, BorderLayout.CENTER); final SpeedSearchBase<JBTable> speedSearch = new SpeedSearchBase<JBTable>(myTable) { public int getSelectedIndex() { return myTable.getSelectedRow(); } @Override protected int convertIndexToModel(int viewIndex) { return myTable.convertRowIndexToModel(viewIndex); } public Object[] getAllElements() { final int count = myTableModel.getRowCount(); Object[] elements = new Object[count]; for (int idx = 0; idx < count; idx++) { elements[idx] = myTableModel.getModuleAt(idx); } return elements; } public String getElementText(Object element) { return ((Module) element).getName() + " (" + FileUtil.toSystemDependentName(((Module) element).getModuleFilePath()) + ")"; } public void selectElement(Object element, String selectedText) { final int count = myTableModel.getRowCount(); for (int row = 0; row < count; row++) { if (element.equals(myTableModel.getModuleAt(row))) { final int viewRow = myTable.convertRowIndexToView(row); myTable.getSelectionModel().setSelectionInterval(viewRow, viewRow); TableUtil.scrollSelectionToVisible(myTable); break; } } } }; speedSearch.setComparator(new SpeedSearchComparator(false)); }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { // Whether we are printing the result or not boolean isPaintingForPrint = false; // Title icon Icon sortIcon = null; if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { Color fgColor = null; Color bgColor = null; if (hasFocus) { fgColor = UIManager.getColor("TableHeader.focusCellForeground"); bgColor = UIManager.getColor("TableHeader.focusCellBackground"); } if (fgColor == null) { fgColor = header.getForeground(); } if (bgColor == null) { bgColor = header.getBackground(); } setForeground(fgColor); setBackground(bgColor); setFont(header.getFont()); isPaintingForPrint = header.isPaintingForPrint(); } if (!isPaintingForPrint && table.getRowSorter() != null) { if (!horizontalTextPositionSet) { // There is a row sorter, and the developer hasn't // set a text position, change to leading. setHorizontalTextPosition(JLabel.LEADING); } List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys(); if (sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) { switch (sortKeys.get(0).getSortOrder()) { case ASCENDING: sortIcon = UIManager.getIcon("Table.ascendingSortIcon"); break; case DESCENDING: sortIcon = UIManager.getIcon("Table.descendingSortIcon"); break; case UNSORTED: sortIcon = UIManager.getIcon("Table.naturalSortIcon"); break; } } } } setIcon(sortIcon); // Title text setText(value == null ? "" : value.toString()); // Title margin setMargin(WebTableStyle.headerMargin); return this; }