public CenterPanel(RegisterPanel rp) {
   super();
   setLayout(new BorderLayout());
   this.rp = rp;
   rp.setJT(jt);
   JScrollPane jsp = new JScrollPane(jt);
   setBackground(Color.BLACK);
   add(jsp, BorderLayout.CENTER);
   tm = (DefaultTableModel) jt.getModel();
   tm.addColumn("ID");
   tm.addColumn("Barcode");
   tm.addColumn("Name");
   tm.addColumn("Qty");
   tm.addColumn("Price");
   tm.addColumn("Tax");
   tm.addColumn("Total");
   // tm.setRowCount(50);
   // jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   jt.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
   jt.getColumnModel().getColumn(0).setPreferredWidth(20);
   jt.getColumnModel().getColumn(1).setPreferredWidth(150);
   jt.getColumnModel().getColumn(2).setPreferredWidth(300);
   jt.getColumnModel().getColumn(3).setPreferredWidth(20);
   jt.setFont(new Font("Arial", Font.BOLD, 18));
   jt.setRowHeight(30);
 }
  // Initializes this component.
  private void jbInit() {
    segmentTable.addFocusListener(
        new FocusListener() {
          public void focusGained(FocusEvent e) {
            segmentTable_focusGained(e);
          }

          public void focusLost(FocusEvent e) {
            segmentTable_focusLost(e);
          }
        });
    segmentTable.setTableHeader(null);
    scrollPane = new JScrollPane(segmentTable);
    scrollPane.setMinimumSize(new Dimension(getTableWidth(), 0));

    setLayout(new BorderLayout(0, 0));

    determineColumnWidth();
    nameLbl.setPreferredSize(new Dimension(getTableWidth(), 25));
    nameLbl.setMinimumSize(new Dimension(getTableWidth(), 0));
    nameLbl.setFont(Utilities.labelsFont);

    segmentTable.setFont(Utilities.valueFont);
    setBorder(BorderFactory.createEtchedBorder());

    setMinimumSize(new Dimension(getTableWidth(), 0));

    this.add(nameLbl, BorderLayout.NORTH);
    this.add(scrollPane, BorderLayout.CENTER);
  }
  @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)
示例#4
0
  public EmpMain() {
    String[] col = {"사번", "이름", "직위", "입사일", "부서번호"};
    String[][] row = new String[0][5];
    model =
        new DefaultTableModel(row, col) {
          public boolean isCellEditable(int r, int c) {
            return false;
          }
        };
    table = new JTable(model);
    JScrollPane js = new JScrollPane(table);
    la = new JLabel("사원목록");
    la.setFont(new Font("나눔스퀘어", Font.BOLD, 30));
    table.setFont(new Font("나눔스퀘어", Font.PLAIN, 12));
    JPanel p = new JPanel();
    p.add(la);

    la1 = new JLabel("Search");
    tf = new JTextField(10);
    box = new JComboBox();
    box.addItem("이름");
    box.addItem("입사일");
    box.addItem("부서");
    b1 = new JButton("찾기");
    b2 = new JButton("목록");
    JPanel p1 = new JPanel();
    p1.add(la1);
    p1.add(box);
    p1.add(tf);
    p1.add(b1);
    p1.add(b2);
    add("South", p1);
    add("Center", js);
    add("North", p);
    setSize(640, 480);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    getData();
    table.addMouseListener(this);
    b1.addActionListener(this);
    b2.addActionListener(this);
  }
  public JComponent createContestantList() {
    JPanel contListPanel = new JPanel();

    MyTableModel contTable = new MyTableModel();

    JTable table = new JTable(contTable);

    table.setPreferredScrollableViewportSize(new Dimension(WIDTH, HEIGHT));
    table.setFillsViewportHeight(true);
    table.setAutoCreateRowSorter(true);
    table.setRowHeight(77);

    table.setFont(new Font("Viner Hand ITC", Font.PLAIN, 18));
    table.setForeground(Color.BLUE);
    table.setSelectionForeground(Color.RED);
    table.setSelectionBackground(
        new Color(0, 0, 0, 64)); // When a cell is selected, this entire row is highlighted.

    // Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    contListPanel.add(scrollPane);

    return contListPanel;
  }
示例#6
0
  public void setContent(String cat) {
    cat = cat.trim();
    selectAllCB.setVisible(false);
    selectAllCB.setSelected(false);
    deleteBut.setVisible(false);
    restoreBut.setVisible(false);
    refreshBut.setVisible(true);
    Object columns[] = null;
    int count = 0;
    switch (cat) {
      case "Inbox":
        columns = new Object[] {"", "From", "Date", "Subject", "Content"};
        count = Database.getCount("Inbox");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='inbox' ORDER BY msg_id desc");
        ;
        break;
      case "SentMail":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Sentmail");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='sentmail' ORDER BY msg_id desc");
        break;
      case "Draft":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Draft");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='draft' ORDER BY msg_id desc");
        break;
      case "Outbox":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Outbox");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='outbox' ORDER BY msg_id desc");
        break;
      case "Trash":
        //                restoreBut.setVisible(true);
        columns = new Object[] {"", "To/From", "Date", "Subject", "Content"};
        count = Database.getCount("Trash");
        workingSet =
            db.getData(
                "SELECT * FROM messages,trash WHERE messages.tag='trash' and messages.msg_id=trash.msg_id ORDER BY deleted_at desc");
        break;
      default:
        System.out.println("in default case");
    }
    if (count > 0) {
      selectAllCB.setVisible(true);
      rows = new Object[count][];
      msgID = new int[count];
      try {
        workingSet.beforeFirst();
        for (int i = 0; i < count && workingSet.next(); i++) {
          msgID[i] = workingSet.getInt(1);
          rows[i] =
              new Object[] {
                false,
                workingSet.getString(2),
                workingSet.getDate(3),
                workingSet.getString(4),
                workingSet.getString(5)
              };
        }
      } catch (SQLException sqlExc) {
        JOptionPane.showMessageDialog(null, sqlExc, "EXCEPTION", JOptionPane.ERROR_MESSAGE);
        sqlExc.printStackTrace();
      }

      tableModel = new MyDefaultTableModel(rows, columns);
      table = new JTable(tableModel);
      table.getSelectionModel().addListSelectionListener(this);
      table.addMouseListener(this);
      table.getTableHeader().setOpaque(true);
      table.getTableHeader().setReorderingAllowed(false);
      //            table.getTableHeader().setBackground(Color.blue);
      table.getTableHeader().setForeground(Color.blue);
      //        table.setRowSelectionAllowed(false);
      //            table.setColumnSelectionAllowed(false);
      table.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14));
      table.setRowHeight(20);
      table.setFillsViewportHeight(true);

      TableColumn column = null;
      for (int i = 0; i < 5; i++) {
        column = table.getColumnModel().getColumn(i);
        if (i == 0) {
          column.setPreferredWidth(6);
        } else if (i == 3) {
          column.setPreferredWidth(250);
        } else if (i == 4) {
          column.setPreferredWidth(450);
        } else {
          column.setPreferredWidth(40);
        }
      }
      table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

      remove(contentPan);
      contentPan = new JScrollPane(table);
      contentPan.setBackground(Color.orange);
      contentPan.setOpaque(true);
      contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      add(contentPan, "Center");
      Home.home.homeFrame.setVisible(true);
    } else {
      JPanel centPan = new JPanel(new GridBagLayout());
      centPan.setBackground(new Color(52, 86, 70));
      JLabel label = new JLabel("No Messages In This Category");
      label.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 22));
      label.setForeground(Color.orange);
      centPan.add(label);
      remove(contentPan);
      contentPan = new JScrollPane(centPan);
      contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      add(contentPan, "Center");
      contentPan.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();
  }