Search in sources :

Example 1 with AudioTableModel

use of me.ruslanys.vkmusic.ui.model.AudioTableModel in project selenium_java by sergueik.

the class MainFrame method initMainPanel.

@Override
protected JPanel initMainPanel() {
    JPanel panel = new JPanel(new BorderLayout(0, 0));
    final JScrollPane scrollPane = new JScrollPane();
    panel.add(scrollPane, BorderLayout.CENTER);
    table = new JTable() {

        @Override
        public Class<?> getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }
    };
    model = new AudioTableModel();
    table.setModel(model);
    table.setTransferHandler(new TransferHandler() {

        @Override
        public void exportToClipboard(JComponent comp, Clipboard clip, int action) {
            int selectedRow = table.getSelectedRow();
            String artist = model.getValueAt(selectedRow, 1).toString();
            String title = model.getValueAt(selectedRow, 2).toString();
            StringSelection selection = new StringSelection(artist + " - " + title);
            clip.setContents(selection, null);
        }
    });
    DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
    centerRenderer.setHorizontalAlignment(JLabel.CENTER);
    table.getColumnModel().getColumn(0).setPreferredWidth(50);
    table.getColumnModel().getColumn(0).setMaxWidth(100);
    table.getColumnModel().getColumn(1).setPreferredWidth(200);
    table.getColumnModel().getColumn(2).setPreferredWidth(200);
    table.getColumnModel().getColumn(3).setCellRenderer(centerRenderer);
    table.getColumnModel().getColumn(3).setPreferredWidth(55);
    table.getColumnModel().getColumn(3).setMaxWidth(70);
    table.getColumnModel().getColumn(4).setPreferredWidth(55);
    table.getColumnModel().getColumn(4).setMaxWidth(70);
    scrollPane.setViewportView(table);
    final JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);
    toolBar.setMargin(new Insets(0, 5, 0, 0));
    panel.add(toolBar, BorderLayout.SOUTH);
    toolbarLabel = new JLabel("...");
    toolBar.add(toolbarLabel);
    return panel;
}
Also used : StringSelection(java.awt.datatransfer.StringSelection) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Clipboard(java.awt.datatransfer.Clipboard) AudioTableModel(me.ruslanys.vkmusic.ui.model.AudioTableModel)

Aggregations

Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)1 AudioTableModel (me.ruslanys.vkmusic.ui.model.AudioTableModel)1