Package de.turniere.test

Source Code of de.turniere.test.TableFrameTest

package de.turniere.test;

import java.awt.BorderLayout;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetAdapter;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.TransferHandler;
import javax.swing.table.DefaultTableModel;

public class TableFrameTest extends JFrame {
 
  private static final int WIDTH = 400;
  private static final int HEIGHT = 300;
 
  public TableFrameTest(){
   
    setSize(WIDTH, HEIGHT);
    setLayout(new BorderLayout());

    Tablabel tl = new Tablabel();
    tl.setText("Achim");
    SPPButton sppbtn = new SPPButton();
   
    //Object [] data1 = {tl, sppbtn, new TestPanel()};
    //Object [] data2 = {new Tablabel(), sppbtn, new TestPanel()};
   
    Object [] data1 = {"s1", "s2", "s2"};
    Object [] data2 = {"s21", "s22", "s22"};
    Object [] data3 = {"s221", "s222", "s222"};
    String[] header = {"abc", "cde", "def"};
    DefaultTableModel model = new DefaultTableModel();
    model.setColumnIdentifiers(header);
    model.addRow(data1);
    model.addRow(data2);
    model.addRow(data3);
    JTable table = new JTable(model);
    //table.setDefaultRenderer(JPanel.class, new TestPanel());
    /*table.getColumnModel().getColumn(0).setCellRenderer(new Tablabel());
    table.getColumnModel().getColumn(1).setCellRenderer(new SPPButton());
    table.getColumnModel().getColumn(2).setCellRenderer(new TestPanel());*/
    /*table.addMouseMotionListener(new MouseMotionListener() {
      public void mouseDragged(MouseEvent e) {
        e.consume();
        JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            handler.exportAsDrag(c, e, TransferHandler.MOVE);
      }

      public void mouseMoved(MouseEvent e) {
      }
    });*/
    table.setSelectionMode( ListSelectionModel.SINGLE_SELECTION);
    table.setDragEnabled( true );
    table.setDropTarget( new DropTarget( table,
        new DropTargetAdapter() {
      public void drop(DropTargetDropEvent dtde) {
      }
    }
    ));
    //table.addMouseListener(new JTableButtonMouseListener(table));
    setLayout(new BorderLayout());
    add(table.getTableHeader(), BorderLayout.PAGE_START);
    add(table, BorderLayout.CENTER);

  }

  /**
   * @param args
   */
  public static void main(String[] args) {
   
    TableFrameTest frame = new TableFrameTest();
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setVisible(true);

  }

}
TOP

Related Classes of de.turniere.test.TableFrameTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.