コード例 #1
0
ファイル: SwingDnDTest.java プロジェクト: hwp0710/javabread
  public SwingDnDFrame() {
    setTitle("SwingDnDTest");
    JTabbedPane tabbedPane = new JTabbedPane();

    JList list = SampleComponents.list();
    tabbedPane.addTab("List", list);
    JTable table = SampleComponents.table();
    tabbedPane.addTab("Table", table);
    JTree tree = SampleComponents.tree();
    tabbedPane.addTab("Tree", tree);
    JFileChooser fileChooser = new JFileChooser();
    tabbedPane.addTab("File Chooser", fileChooser);
    JColorChooser colorChooser = new JColorChooser();
    tabbedPane.addTab("Color Chooser", colorChooser);

    final JTextArea textArea = new JTextArea(4, 40);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Drag text here"));

    JTextField textField = new JTextField("Drag color here");
    textField.setTransferHandler(new TransferHandler("background"));

    tabbedPane.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            textArea.setText("");
          }
        });

    tree.setDragEnabled(true);
    table.setDragEnabled(true);
    list.setDragEnabled(true);
    fileChooser.setDragEnabled(true);
    colorChooser.setDragEnabled(true);
    textField.setDragEnabled(true);

    add(tabbedPane, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(textField, BorderLayout.SOUTH);
    pack();
  }
コード例 #2
0
ファイル: InputPanel.java プロジェクト: 4ment/beast-mcmc
  public InputPanel(
      final TreeSpaceFrame parent, final TreeSpaceDocument document, final Action addDataAction) {

    this.frame = parent;
    this.document = document;

    dataTableModel = new DataTableModel();
    dataTable = new JTable(dataTableModel);

    dataTable.getTableHeader().setReorderingAllowed(false);
    //        dataTable.getTableHeader().setDefaultRenderer(
    //                new HeaderRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));

    TableColumn col = dataTable.getColumnModel().getColumn(0);
    col.setCellRenderer(new MultiLineTableCellRenderer());

    dataTable.setRowHeight(dataTable.getRowHeight() * 2);

    dataTable.setDragEnabled(false);
    dataTable.setTransferHandler(new FSTransfer());

    TableEditorStopper.ensureEditingStopWhenTableLosesFocus(dataTable);

    dataTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent evt) {
                selectionChanged();
              }
            });

    dataTable.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              editSelection();
            }
          }
        });

    scrollPane =
        new JScrollPane(
            dataTable,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane.setOpaque(false);

    //        JToolBar toolBar1 = new JToolBar();
    //        toolBar1.setFloatable(false);
    //        toolBar1.setOpaque(false);
    //        toolBar1.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));

    //        JButton button = new JButton(unlinkModelsAction);
    //        unlinkModelsAction.setEnabled(false);
    //        PanelUtils.setupComponent(button);
    //        toolBar1.add(button);

    ActionPanel actionPanel1 = new ActionPanel(true);
    actionPanel1.setAddAction(addDataAction);
    actionPanel1.setRemoveAction(removeAction);

    removeAction.setEnabled(false);

    JPanel controlPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    controlPanel1.setOpaque(false);
    controlPanel1.add(actionPanel1);

    setOpaque(false);
    setBorder(new BorderUIResource.EmptyBorderUIResource(new Insets(12, 12, 12, 12)));
    setLayout(new BorderLayout(0, 0));
    //        add(toolBar1, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(controlPanel1, BorderLayout.SOUTH);

    document.addListener(
        new TreeSpaceDocument.Listener() {
          public void dataChanged() {
            dataTableModel.fireTableDataChanged();
          }

          public void settingsChanged() {}
        });
  }
コード例 #3
0
  public JComponent createComponentImpl() {
    final DefaultTableModel tableModel = createModel();
    myTable = new JBTable(tableModel);
    myTable.setIntercellSpacing(new Dimension(0, 0));
    myTable.setDefaultRenderer(TableItem.class, new MyRenderer());
    myTable.setShowGrid(false);
    myTable.setDragEnabled(false);
    myTable.setShowHorizontalLines(false);
    myTable.setShowVerticalLines(false);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    JPanel tablePanel =
        ToolbarDecorator.createDecorator(myTable)
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    FileChooserDescriptor myDescriptor =
                        FileChooserDescriptorFactory.createSingleFolderDescriptor();
                    myDescriptor.setTitle(
                        ProjectBundle.message("add.external.annotations.path.title"));
                    myDescriptor.setDescription(
                        ProjectBundle.message("add.external.annotations.path.description"));
                    VirtualFile[] files =
                        FileChooser.chooseFiles(myDescriptor, myTable, myProject, null);
                    final MyTableModel tableModel = (MyTableModel) myTable.getModel();
                    boolean changes = false;
                    for (final VirtualFile file : files) {
                      if (file != null) {
                        tableModel.addTableItem(new TableItem(file));
                        changes = true;
                      }
                    }
                    if (changes) {
                      saveData();
                      TableUtil.selectRows(myTable, new int[] {tableModel.getRowCount() - 1});
                    }
                  }
                })
            .setRemoveAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    final List removedItems = TableUtil.removeSelectedItems(myTable);
                    if (removedItems.size() > 0) {
                      saveData();
                    }
                  }
                })
            .createPanel();

    final JPanel mainPanel = new JPanel(new BorderLayout());

    mainPanel.add(tablePanel, BorderLayout.CENTER);
    mainPanel.add(
        new JBLabel(
            ProjectBundle.message("project.roots.external.annotations.description"),
            UIUtil.ComponentStyle.SMALL,
            UIUtil.FontColor.BRIGHTER),
        BorderLayout.NORTH);
    return mainPanel;
  }
コード例 #4
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();
  }
コード例 #5
0
ファイル: GenXml.java プロジェクト: abel533/EasyXls
  /** 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);
  }
コード例 #6
0
ファイル: AnnotationsEditor.java プロジェクト: jexp/idea2
  public JComponent createComponentImpl() {
    final JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
    mainPanel.setPreferredSize(new Dimension(-1, 200));
    final DefaultTableModel tableModel = createModel();
    myTable = new Table(tableModel);
    myTable.setIntercellSpacing(new Dimension(0, 0));
    myTable.setDefaultRenderer(TableItem.class, new MyRenderer());
    myTable.setShowGrid(false);
    myTable.setDragEnabled(false);
    myTable.setShowHorizontalLines(false);
    myTable.setShowVerticalLines(false);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    myAddPathButton = new JButton(ProjectBundle.message("module.javadoc.add.path.button"));
    myAddPathButton.addActionListener(new AddPathActionListener());

    myRemoveButton = new JButton(ProjectBundle.message("module.javadoc.remove.button"));
    myRemoveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List removedItems = TableUtil.removeSelectedItems(myTable);
            if (removedItems.size() > 0) {
              saveData();
            }
          }
        });

    final JPanel panel = new JPanel(new GridBagLayout());
    panel.add(
        myAddPathButton,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTH,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 6, 0, 0),
            0,
            0));
    panel.add(
        myRemoveButton,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTH,
            GridBagConstraints.HORIZONTAL,
            new Insets(6, 6, 0, 0),
            0,
            0));

    mainPanel.add(ScrollPaneFactory.createScrollPane(myTable), BorderLayout.CENTER);
    mainPanel.add(panel, BorderLayout.EAST);
    final PanelWithText panelWithText =
        new PanelWithText(ProjectBundle.message("project.roots.external.annotations.description"));
    panelWithText.setBorder(null);
    mainPanel.add(panelWithText, BorderLayout.NORTH);

    myTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                  return;
                }
                final int selectedIndex = myTable.getSelectedRow();
                myRemoveButton.setEnabled(selectedIndex >= 0);
              }
            });
    if (tableModel.getRowCount() > 0) {
      TableUtil.selectRows(myTable, new int[] {0});
    } else {
      myRemoveButton.setEnabled(false);
    }
    return mainPanel;
  }
コード例 #7
0
  public DefaultDnDSupport() {
    JFrame fen = new JFrame("DnD et CCP");
    fen.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
    fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Panel gauche
    JPanel panelgauche = new JPanel();
    panelgauche.setLayout(new BoxLayout(panelgauche, BoxLayout.Y_AXIS));

    // JTextField
    JTextField textField = new JTextField(10);
    textField.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JTextField"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    textField.setDragEnabled(true);

    // JPasswordField
    JPasswordField passwordField = new JPasswordField(10);
    passwordField.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JPasswordField"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    passwordField.setDragEnabled(true);

    // JFormattedTextField
    JFormattedTextField ftf = new JFormattedTextField("Universite de Lille 1");
    ftf.setFont(new Font("Courier", Font.ITALIC, 12));
    ftf.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JFormattedTextField"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    ftf.setDragEnabled(true);

    // JTextArea
    JTextArea jta = new JTextArea("Master 1 informatique");
    jta.setFont(new Font("Arial", Font.BOLD, 12));
    jta.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JTextArea"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    jta.setDragEnabled(true);

    // JEditorPane
    JEditorPane editorPane = createEditorPane();
    editorPane.setDragEnabled(true);
    JScrollPane editorScrollPane = new JScrollPane(editorPane);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JEditorPane"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // JColorChooser
    JColorChooser cc = new JColorChooser();
    cc.setDragEnabled(true);
    cc.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JColorChooser"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Panel droit
    JPanel paneldroit = new JPanel();
    paneldroit.setLayout(new BoxLayout(paneldroit, BoxLayout.Y_AXIS));

    // JList
    String[] data = {
      "AAC", "AEV", "ANG", "ASE", "COA", "PJE", "CAR", "PJI", "AeA", "BDA", "CALP", "FDD", "HECI",
      "IHM", "M3DS", "PAC", "PPD", "RdF", "SVL", "TI"
    };
    JList liste = new JList(data);
    JScrollPane jscrollListe = new JScrollPane(liste);
    jscrollListe.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JList"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    // liste.setDragEnabled(true);

    // JTree
    DefaultMutableTreeNode m1 = new DefaultMutableTreeNode("M1");
    DefaultMutableTreeNode s1 = new DefaultMutableTreeNode("S1");
    m1.add(s1);
    s1.add(new DefaultMutableTreeNode("AAC"));
    s1.add(new DefaultMutableTreeNode("AEV"));
    s1.add(new DefaultMutableTreeNode("ANG"));
    s1.add(new DefaultMutableTreeNode("ASE"));
    s1.add(new DefaultMutableTreeNode("COA"));
    s1.add(new DefaultMutableTreeNode("PJE"));
    DefaultMutableTreeNode s2 = new DefaultMutableTreeNode("S2");
    m1.add(s2);
    s2.add(new DefaultMutableTreeNode("CAR"));
    s2.add(new DefaultMutableTreeNode("PJI"));
    s2.add(new DefaultMutableTreeNode("AeA"));
    s2.add(new DefaultMutableTreeNode("BDA"));
    s2.add(new DefaultMutableTreeNode("CALP"));
    s2.add(new DefaultMutableTreeNode("FDD"));
    s2.add(new DefaultMutableTreeNode("HECI"));
    s2.add(new DefaultMutableTreeNode("IHM"));
    s2.add(new DefaultMutableTreeNode("M3DS"));
    s2.add(new DefaultMutableTreeNode("PAC"));
    s2.add(new DefaultMutableTreeNode("PPD"));
    s2.add(new DefaultMutableTreeNode("RdF"));
    s2.add(new DefaultMutableTreeNode("SVL"));
    s2.add(new DefaultMutableTreeNode("TI"));
    JTree tree = new JTree(m1);
    // tree.setDragEnabled(true);
    JScrollPane jscrollTree = new JScrollPane(tree);
    jscrollTree.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JTree"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    jscrollTree.setPreferredSize(new Dimension(200, 200));

    // JTable
    String[] columnNames = {"S1", "S2"};
    Object[][] data2 = {
      {"AAC", "CAR"},
      {"AEV", "PJI"},
      {"ANG", "AeA"},
      {"ASE", "BDA"},
      {"COA", "CALP"},
      {"PJE", "FDD"},
      {"", "HECI"},
      {"", "IHM"},
      {"", "M3DS"},
      {"", "PAC"},
      {"", "PPD"},
      {"", "RdF"},
      {"", "SVL"},
      {"", "TI"}
    };

    JTable table = new JTable(data2, columnNames);
    JScrollPane scrollPaneTable = new JScrollPane(table);
    table.setDragEnabled(true);

    // JFileChooser
    JFileChooser fc = new JFileChooser();
    fc.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JFileChooser"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    fc.setDragEnabled(true);

    panelgauche.add(textField);
    panelgauche.add(passwordField);
    panelgauche.add(ftf);
    panelgauche.add(jta);
    panelgauche.add(cc);
    panelgauche.add(editorScrollPane);
    fen.getContentPane().add(panelgauche);

    paneldroit.add(fc);
    paneldroit.add(jscrollListe);
    paneldroit.add(jscrollTree);
    paneldroit.add(scrollPaneTable);

    fen.getContentPane().add(paneldroit);

    fen.pack();
    fen.setVisible(true);
  }