Exemplo n.º 1
0
 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);
  }
Exemplo n.º 3
0
  public hostelStatus() {
    setTitle("Hostel");
    connect();
    updateRecord();

    JFrame fr = new JFrame();
    Toolkit tkt = fr.getToolkit();
    Dimension frsize = tkt.getScreenSize();
    setBounds(frsize.width / 4, frsize.height / 12, frsize.width / 2, frsize.height / 8);
    setLayout(null);

    cn = getContentPane();
    cn.setBackground(new Color(190, 180, 170));

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    tl = new JLabel("Current Hostels Status");
    tl.setFont(new Font("Engravers MT", 1, 25));
    tl.setForeground(new Color(247, 251, 249));

    p1 = new JPanel();
    p1.setBounds(0, 0, 600, 50);
    p1.add(tl);
    p1.setBackground(new Color(31, 88, 166));
    cn.add(p1);

    b1 = new JButton("LOAD");
    b1.setMnemonic('L');
    b1.addActionListener(new dispListener());
    b1.setBounds(230, 320, 120, 30);

    b2 = new JButton("EXIT");
    b2.setMnemonic('X');
    b2.addActionListener(new exitListener());
    b2.setBounds(350, 320, 100, 30);

    cn.add(b1);
    cn.add(b2);

    table = new JTable(data, col);
    table.setFont(new Font("Serif", Font.BOLD, 16));
    table.setBackground(new Color(250, 250, 250));
    table.setEnabled(false);

    JScrollPane jsp = new JScrollPane(table);
    jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jsp.setBounds(5, 100, 590, 200);
    cn.add(jsp);

    screensize = Toolkit.getDefaultToolkit().getScreenSize();

    setSize(600, 400);
    setVisible(true);
    setVisible(true);
    setResizable(true);
    connect();
  }
  public TeacherManagePasswords() {
    super(new BorderLayout());
    setBackground(FWCConfigurator.bgColor);

    // Build title and north panel
    pnNorth = new JPanel(new FlowLayout(FlowLayout.CENTER));
    pnNorth.setBackground(FWCConfigurator.bgColor);
    lblTitle = new TitleLabel("Reset Passwords", FWCConfigurator.RESET_PASSW_TITLE_IMG);
    pnNorth.add(lblTitle);

    // Build center panel
    pnCenter = new JPanel(new BorderLayout());
    pnCenter.setBackground(FWCConfigurator.bgColor);

    // Build table of students
    tableModel = new DisabledTableModel();
    tableModel.setColumnIdentifiers(
        new String[] {"First Name", " Last " + "Name", "Username", "Class"});

    studentsTable = new JTable(tableModel);
    studentsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    studentsTable.setFillsViewportHeight(true);
    studentsTable.getTableHeader().setFont(new Font("Calibri", Font.PLAIN, 18));
    studentsTable.setFont(new Font("Calibri", Font.PLAIN, 18));
    studentsTable.setRowHeight(studentsTable.getRowHeight() + 12);

    // Populate the table only with students that need a password reset
    students = FWCConfigurator.getTeacher().getStudentsRequestedReset();
    populateTable();

    tableScroll =
        new JScrollPane(
            studentsTable,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    tableScroll.setBackground(FWCConfigurator.bgColor);
    tableScroll.setBorder(
        BorderFactory.createCompoundBorder(
            new EmptyBorder(10, 100, 10, 100), new LineBorder(Color.black, 1)));

    pnCenter.add(tableScroll, BorderLayout.CENTER);

    // Build south panel
    pnButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));
    pnButtons.setBackground(FWCConfigurator.bgColor);
    pnButtons.setBorder(BorderFactory.createEmptyBorder(0, 100, 20, 100));
    btnReset = new ImageButton("Reset Selected", FWCConfigurator.RESET_SELECTED_IMG, 150, 50);
    btnReset.addActionListener(new ResetListener());
    btnResetAll = new ImageButton("Reset All", FWCConfigurator.RESET_ALL_IMG, 150, 50);
    btnResetAll.addActionListener(new ResetListener());
    pnButtons.add(btnReset);
    pnButtons.add(btnResetAll);

    this.add(pnNorth, BorderLayout.NORTH);
    this.add(pnCenter, BorderLayout.CENTER);
    this.add(pnButtons, BorderLayout.SOUTH);
  }
Exemplo n.º 5
0
 private void jbInit() throws Exception {
   setTitle("DIARIO CONTADO");
   frmDatosVenta = new FrmDatosVenta(engine);
   frmDatosVenta.setLocationRelativeTo(this);
   getContentPane().setLayout(borderLayout1);
   jLabel1.setFont(new java.awt.Font("Arial", Font.PLAIN, 18));
   jLabel1.setToolTipText("");
   jLabel1.setText("DIARIO DE ENTRADAS");
   pnlCentro.setLayout(borderLayout2);
   cmdCerrar.setText("CERRAR");
   cmdCerrar.addActionListener(new FrmDiarioDeEntradas_cmdCerrar_actionAdapter(this));
   cmdImprimir.setText("IMPRIMIR");
   tblDiario.setBackground(new Color(255, 240, 255));
   tblDiario.setFont(new java.awt.Font("Arial", Font.PLAIN, 12));
   tblDiario.setModel(modelDiarioVentasDeContado1);
   tblDiario.addMouseListener(new FrmDiarioDeEntradas_tblDiario_mouseAdapter(this));
   this.addWindowListener(new FrmDiarioDeEntradas_this_windowAdapter(this));
   jLabel2.setFont(new java.awt.Font("Arial", Font.BOLD, 20));
   jLabel2.setText("Total:");
   lblTotal.setFont(new java.awt.Font("Arial", Font.BOLD, 20));
   lblTotal.setText("");
   this.getContentPane().setBackground(Color.white);
   this.addKeyListener(new FrmDiarioDeEntradas_this_keyAdapter(this));
   pnlCentro.setBackground(Color.white);
   pnlNorte.setBackground(Color.white);
   pnlNorte.setLayout(borderLayout4);
   scrollDiario.getViewport().setBackground(Color.white);
   scrollDiario.setPreferredSize(new Dimension(800, 600));
   lblFecha.setFont(new java.awt.Font("Arial", Font.BOLD, 16));
   lblFecha.setText("");
   jPanel1.setLayout(borderLayout3);
   pnlSur.setMaximumSize(new Dimension(4000, 200));
   jPanel1.setBackground(Color.white);
   jPanel2.setBackground(Color.white);
   this.getContentPane().add(pnlCentro, java.awt.BorderLayout.CENTER);
   pnlCentro.add(pnlNorte, java.awt.BorderLayout.CENTER);
   pnlCentro.add(scrollDiario, java.awt.BorderLayout.NORTH);
   scrollDiario.getViewport().add(tblDiario);
   this.getContentPane().add(pnlSur, java.awt.BorderLayout.SOUTH);
   pnlSur.add(cmdImprimir);
   pnlSur.add(cmdCerrar);
   this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
   jPanel1.add(lblFecha, java.awt.BorderLayout.EAST);
   jPanel1.add(jLabel1, java.awt.BorderLayout.WEST);
   pnlNorte.add(jPanel2, java.awt.BorderLayout.EAST);
   jPanel2.add(jLabel2);
   jPanel2.add(lblTotal);
   this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
 }
Exemplo n.º 6
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);
  }
  void tableInitialise(JTable table) {

    JScrollPane scroll;
    TableColumn column = null;

    int colunms = table.getColumnCount();
    for (int y = 0; y < colunms; y++) {
      column = table.getColumnModel().getColumn(y);
      /*将每一列的默认宽度设置为100*/
      column.setPreferredWidth(100);
    }
    /*
     * 设置JTable自动调整列表的状态,此处设置为关闭
     */
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    table.setFont(new Font("Menu.font", Font.PLAIN, 14));
    table.getTableHeader().setFont(new Font("Menu.font", Font.BOLD, 15));
    /*用JScrollPane装载JTable,这样超出范围的列就可以通过滚动条来查看*/

    scroll = new JScrollPane(table);
    TablePanel.removeAll();

    TablePanel.setLayout(new BoxLayout(TablePanel, BoxLayout.Y_AXIS));
    TablePanel.add(scroll);

    TablePanel.revalidate();

    table.setRowSelectionAllowed(true); // 设置JTable可被选择
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 设置JTable为单行选择
    table.getTableHeader().setBackground(new Color(206, 231, 255)); // 设置JTable表头颜色
    table.getTableHeader().setReorderingAllowed(false); // 设置JTable每个字段的顺序不可以改变
    table.getTableHeader().setResizingAllowed(false); // 设置JTable每个表头的大小不可以改变
    makeFace(table); // 设置JTable 颜色

    table.setVisible(true);
  }
  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;
  }
Exemplo n.º 9
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();
    }
  }
Exemplo n.º 10
0
  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();
  }
Exemplo n.º 11
0
  /** Create the frame. */
  public GenXml() {
    setResizable(false);
    setTitle("XML生成向导");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 670, 500);
    contentPane = new JPanel();
    contentPane.setBorder(new LineBorder(Color.DARK_GRAY, 4));
    setContentPane(contentPane);
    contentPane.setLayout(new BorderLayout(0, 0));

    btnpanel = new JPanel();
    btnpanel.setBackground(Color.DARK_GRAY);
    btnpanel.setBorder(new LineBorder(Color.DARK_GRAY));
    btnpanel.setPreferredSize(new Dimension(10, 60));
    contentPane.add(btnpanel, BorderLayout.SOUTH);
    btnpanel.setLayout(null);

    prevBtn = new JButton("上一步");
    prevBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            prev();
          }
        });
    prevBtn.setEnabled(false);
    prevBtn.setBounds(294, 10, 113, 40);
    btnpanel.add(prevBtn);

    nextBtn = new JButton("下一步");
    nextBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            next();
          }
        });
    nextBtn.setBounds(417, 10, 113, 40);
    btnpanel.add(nextBtn);

    doneBtn = new JButton("完成");
    doneBtn.addActionListener(doneListener);
    doneBtn.setEnabled(false);
    doneBtn.setBounds(540, 10, 113, 40);
    btnpanel.add(doneBtn);

    card = new CardLayout(0, 0);
    pane = new JPanel(card);
    contentPane.add(pane, BorderLayout.CENTER);

    step1 = new JPanel();
    step1.setBackground(Color.LIGHT_GRAY);
    step1.setBorder(new LineBorder(new Color(0, 0, 0)));
    pane.add(step1, "name_287780550285180");
    step1.setLayout(null);

    JLabel label = new JLabel("请输入类名(全路径):");
    label.setFont(new Font("宋体", Font.PLAIN, 18));
    label.setBounds(10, 42, 344, 43);
    step1.add(label);

    classPath = new JTextField();
    classPath.setForeground(Color.BLACK);
    classPath.setBackground(Color.WHITE);
    classPath.setFont(new Font("宋体", Font.BOLD, 20));
    classPath.setBounds(10, 95, 636, 52);
    step1.add(classPath);
    classPath.setColumns(10);

    JLabel lblxml = new JLabel("保存xml路径(全路径):");
    lblxml.setFont(new Font("宋体", Font.PLAIN, 18));
    lblxml.setBounds(10, 218, 344, 43);
    step1.add(lblxml);

    filePath = new JTextField();
    // 默认使用当前路径
    String path = GenXml.class.getResource("/").getPath();
    if (path.startsWith("/")) {
      path = path.substring(1);
    }
    filePath.setText(path);
    filePath.setForeground(Color.BLACK);
    filePath.setFont(new Font("宋体", Font.BOLD, 20));
    filePath.setColumns(10);
    filePath.setBackground(Color.WHITE);
    filePath.setBounds(10, 271, 636, 52);
    step1.add(filePath);

    step2 = new JPanel();
    step2.setBackground(Color.LIGHT_GRAY);
    step2.setBorder(new LineBorder(new Color(0, 0, 0)));
    pane.add(step2, "name_287788958231594");
    step2.setLayout(new BorderLayout(0, 0));

    JScrollPane scrollPane = new JScrollPane();
    step2.add(scrollPane);

    table = new JTable();
    table.setRowHeight(30);
    table.setAutoCreateRowSorter(true);
    table.setDragEnabled(true);
    table.setFont(new Font("宋体", Font.PLAIN, 18));
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setForeground(Color.BLACK);
    table.setBackground(Color.WHITE);
    table.setModel(
        new DefaultTableModel(
            new Object[][] {},
            new String[] {"\u5B57\u6BB5\u540D", "\u7C7B\u578B", "\u5217\u540D"}));
    table.getColumnModel().getColumn(0).setPreferredWidth(120);
    table.getColumnModel().getColumn(1).setPreferredWidth(200);
    table.getColumnModel().getColumn(2).setPreferredWidth(120);
    scrollPane.setViewportView(table);

    panel_1 = new JPanel();
    panel_1.setPreferredSize(new Dimension(10, 40));
    step2.add(panel_1, BorderLayout.NORTH);
    panel_1.setLayout(null);

    label_1 = new JLabel("需要显示的属性:");
    label_1.setBounds(10, 10, 157, 22);
    panel_1.add(label_1);

    panel_2 = new JPanel();
    panel_2.setPreferredSize(new Dimension(100, 10));
    step2.add(panel_2, BorderLayout.EAST);
    panel_2.setLayout(null);

    reset = new JButton("重置");
    reset.setBounds(3, 0, 93, 25);
    panel_2.add(reset);

    mvT = new JButton("向上");
    mvT.setBounds(3, 30, 93, 25);
    panel_2.add(mvT);

    mvD = new JButton("向下");
    mvD.setBounds(3, 60, 93, 25);
    panel_2.add(mvD);

    delBtn = new JButton("删除");
    delBtn.setBounds(3, 90, 93, 25);
    panel_2.add(delBtn);
    delBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // 删除选中列
            DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
            int row = table.getSelectedRow();
            if (row > -1) {
              tableModel.removeRow(row);
              if (row < table.getRowCount()) {
                table.getSelectionModel().setSelectionInterval(row, row);
              } else if (row > 1) {
                table.getSelectionModel().setSelectionInterval(row, row);
              }
            }
          }
        });
    mvD.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // 移动选中列
            DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
            int row = table.getSelectedRow();
            if (row < table.getRowCount()) {
              tableModel.moveRow(row, row, ++row);
              table.getSelectionModel().setSelectionInterval(row, row);
            }
          }
        });
    mvT.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // 移动选中列
            DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
            int row = table.getSelectedRow();
            if (row > 0) {
              tableModel.moveRow(row, row, --row);
              table.getSelectionModel().setSelectionInterval(row, row);
            }
          }
        });
    reset.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ReadInTable(classPath.getText());
          }
        });

    step3 = new JPanel();
    step3.setBackground(Color.LIGHT_GRAY);
    step3.setBorder(new LineBorder(new Color(0, 0, 0)));
    pane.add(step3, "name_287798491067114");
    step3.setLayout(new BorderLayout(0, 0));

    JPanel panel = new JPanel();
    panel.setBackground(Color.LIGHT_GRAY);
    panel.setBorder(new LineBorder(new Color(0, 0, 0)));
    step3.add(panel);
    panel.setLayout(null);

    lblsheet = new JLabel("sheet序号:");
    lblsheet.setBounds(106, 226, 99, 15);
    panel.add(lblsheet);

    label_3 = new JLabel("开始行号:");
    label_3.setBounds(106, 291, 99, 24);
    panel.add(label_3);

    lblSheet = new JLabel("sheet名称:");
    lblSheet.setBounds(106, 261, 99, 15);
    panel.add(lblSheet);

    label_4 = new JLabel("是否缓存:");
    label_4.setBounds(106, 191, 99, 15);
    panel.add(label_4);

    cache = new JCheckBox("选中为缓存(不选为不缓存)");
    cache.setSelected(true);
    cache.setBounds(215, 184, 312, 30);
    panel.add(cache);

    sheet = new JTextField();
    sheet.setText("Sheet0");
    sheet.setColumns(10);
    sheet.setBounds(215, 254, 312, 30);
    panel.add(sheet);

    sheetNum = new JTextField();
    sheetNum.setHorizontalAlignment(SwingConstants.CENTER);
    sheetNum.setBackground(Color.DARK_GRAY);
    sheetNum.setForeground(Color.WHITE);
    sheetNum.setEnabled(false);
    sheetNum.setBounds(461, 219, 66, 30);
    panel.add(sheetNum);
    sheetNum.setColumns(10);

    startRow = new JTextField();
    startRow.setHorizontalAlignment(SwingConstants.CENTER);
    startRow.setForeground(Color.WHITE);
    startRow.setBackground(Color.DARK_GRAY);
    startRow.setEnabled(false);
    startRow.setColumns(10);
    startRow.setBounds(461, 289, 66, 30);
    panel.add(startRow);

    sliderRow = new JSlider();
    sliderRow.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            startRow.setText("" + sliderRow.getValue());
          }
        });
    sliderRow.setMaximum(10);
    sliderRow.setValue(0);
    sliderRow.setBounds(215, 289, 240, 30);
    panel.add(sliderRow);

    sliderSheet = new JSlider();
    sliderSheet.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            sheetNum.setText("" + sliderSheet.getValue());
          }
        });
    sliderSheet.setValue(0);
    sliderSheet.setMaximum(10);
    sliderSheet.setBounds(215, 219, 240, 30);
    panel.add(sliderSheet);

    label_2 = new JLabel("           基本信息:");
    label_2.setPreferredSize(new Dimension(60, 35));
    step3.add(label_2, BorderLayout.NORTH);
  }