コード例 #1
0
  public TableCellRenderFrame() {
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    TableModel model = new PlanetTableModel();
    JTable table = new JTable(model);
    table.setRowSelectionAllowed(false);

    // set up renderers and editors

    table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
    table.setDefaultEditor(Color.class, new ColorTableCellEditor());

    JComboBox<Integer> moonCombo = new JComboBox<>();
    for (int i = 0; i <= 20; i++) moonCombo.addItem(i);

    TableColumnModel columnModel = table.getColumnModel();
    TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN);
    moonColumn.setCellEditor(new DefaultCellEditor(moonCombo));
    moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class));
    moonColumn.setHeaderValue(new ImageIcon(getClass().getResource("Moons.gif")));

    // show table

    table.setRowHeight(100);
    add(new JScrollPane(table), BorderLayout.CENTER);
  }
コード例 #2
0
ファイル: SwingTableDemo.java プロジェクト: trabbis/test3
  // This handles the row, column, and cell selection buttons.
  public void actionPerformed(ActionEvent ie) {

    // See which button is selected.
    if (jrbRows.isSelected()) {
      // Enable row selection.
      jtabOrders.setColumnSelectionAllowed(false);
      jtabOrders.setRowSelectionAllowed(true);
    } else if (jrbColumns.isSelected()) {
      // Enable column selection.
      jtabOrders.setColumnSelectionAllowed(true);
      jtabOrders.setRowSelectionAllowed(false);
    } else {
      // Enable cell selection.
      jtabOrders.setCellSelectionEnabled(true);
    }
  }
コード例 #3
0
 private void jbInit() throws Exception {
   panel1.setLayout(borderLayout1);
   okButton.setText("OK");
   okButton.addActionListener(new MimeTypeEditor_okButton_actionAdapter(this));
   filtersTable.setRowSelectionAllowed(true);
   filtersTable.setPreferredSize(new Dimension(418, 200));
   filtersTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
   filtersTable.setCellSelectionEnabled(true);
   filtersTable.setColumnSelectionAllowed(false);
   filtersTable.setModel(m_model);
   addButton.setToolTipText(
       "Add a new " + mimeTypeEditorBuilder.getValueName() + " for a MIME type");
   addButton.setText("Add");
   addButton.addActionListener(new MimeTypeEditor_addButton_actionAdapter(this));
   cancelButton.setText("Cancel");
   cancelButton.addActionListener(new MimeTypeEditor_cancelButton_actionAdapter(this));
   deleteButton.setToolTipText("Delete the currently selected item.");
   deleteButton.setText("Delete");
   deleteButton.addActionListener(new MimeTypeEditor_deleteButton_actionAdapter(this));
   upButton.setText("Up");
   upButton.addActionListener(new MimeTypeEditor_upButton_actionAdapter(this));
   dnButton.setText("Down");
   dnButton.addActionListener(new MimeTypeEditor_dnButton_actionAdapter(this));
   panel1.setPreferredSize(new Dimension(418, 200));
   jScrollPane1.setMinimumSize(new Dimension(200, 80));
   jScrollPane1.setOpaque(true);
   buttonPanel.add(dnButton, null);
   buttonPanel.add(upButton, null);
   buttonPanel.add(addButton, null);
   buttonPanel.add(deleteButton, null);
   buttonPanel.add(okButton, null);
   buttonPanel.add(cancelButton, null);
   getContentPane().add(panel1);
   panel1.add(buttonPanel, BorderLayout.SOUTH);
   panel1.add(jScrollPane1, BorderLayout.CENTER);
   jScrollPane1.getViewport().add(filtersTable, null);
 }
コード例 #4
0
  public FrontEnd() {
    setLocation(0, 0);
    setSize(1285, 750);
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    table =
        new JTable(dtm) {
          @Override
          public boolean isCellEditable(int row, int column) {
            if (column == 0 || column == 1) return false;
            else return true;
          }
        };
    final JComboBox comboBoxRun = new JComboBox();
    comboBoxRun.setEditable(true);
    comboBoxRun.addItem("Run all tests");
    comboBoxRun.addItem("Run all tests and then rerun Failed tests");
    comboBoxRun.addItem("Only run Failed tests");
    table.getColumnModel().getColumn(0).setPreferredWidth(422);
    table.getColumnModel().getColumn(1).setPreferredWidth(460);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setRowSelectionAllowed(false);
    table.getTableHeader().setReorderingAllowed(false);
    table.getTableHeader().setPreferredSize(new Dimension(100, HEADER_HEIGHT));
    table.getTableHeader().setFont(new Font(null, Font.BOLD, 12));
    table.getTableHeader().setBackground(Color.LIGHT_GRAY);
    table.getTableHeader().setPreferredSize(new Dimension(10000, 32));
    JScrollPane sp = new JScrollPane(table);
    JPanel subPanel = new JPanel();
    JPanel subPanel1 = new JPanel();
    openF = new JButton("Choose File");
    openFo = new JButton("Choose Folder");
    selFo = new JButton("Select Single Folder");
    canF = new JButton("Cancel");
    canF.setEnabled(false);
    resLab = new JLabel("Results Path");
    Launch = new JButton("Launch");
    foSel = new JButton("...");
    foSel.setPreferredSize(new Dimension(18, 18));
    resBox = new JTextField(placeS);
    resBox.setPreferredSize(new Dimension(500, 24));
    resBox.setEditable(false);
    duplC = new JCheckBox("Remove Duplicates");
    duplC.setSelected(true);
    subPanel.add(openF);
    subPanel.add(openFo);
    subPanel.add(selFo);
    subPanel.add(canF);
    subPanel.add(Launch);
    subPanel.add(duplC);
    subPanel.add(comboBoxRun);
    subPanel1.add(resLab);
    subPanel1.add(resBox);
    subPanel1.add(foSel);

    initUI();
    getContentPane().add(sp, BorderLayout.CENTER);
    getContentPane().add(subPanel, BorderLayout.SOUTH);
    getContentPane().add(subPanel1, BorderLayout.NORTH);
    sValue = (String) comboBoxRun.getSelectedItem();
    comboBoxRun.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            String sValue = (String) comboBoxRun.getSelectedItem();
            if (sValue.equals("Run all Tests")) {
              flagF = 1;
            }
            if (sValue.contains("Run all tests and then rerun Failed tests")) {
              flagF = 2;
            }
            if (sValue.contains("Only run Failed tests")) {
              flagF = 3;
            }
            System.out.println(flagF);
          }
        });
    openF.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            openFile();
          }
        });
    openFo.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            openFolder();
          }
        });
    selFo.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            selFolder();
          }
        });
    canF.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            cancelSel();
          }
        });
    foSel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            resFol();
            resBox.setText(placeS);
          }
        });
    Launch.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            try {
              doLaunch();
            } catch (IOException ex) {
              Logger.getLogger(FrontEnd.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        });

    table.addMouseListener(
        new java.awt.event.MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
              // Bring up pop up on row/col of right click
              JTable source = (JTable) e.getSource();
              int row = source.rowAtPoint(e.getPoint());
              int column = source.columnAtPoint(e.getPoint());
              if (!source.isRowSelected(row) || !source.isColumnSelected(column))
                source.changeSelection(row, column, false, false);
              doPop(e);
            }
          }
        });
  }
コード例 #5
0
  public static void main(String args[]) {
    // style that is necessary
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
    } catch (InstantiationException e) {
    } catch (IllegalAccessException e) {
    } catch (UnsupportedLookAndFeelException e) {
    }

    // Standard preparation for a frame
    fmain = new JFrame("Schedule Appointments"); // Create and name frame
    fmain.setSize(330, 375); // Set size to 400x400 pixels
    pane = fmain.getContentPane();
    pane.setLayout(null); // Apply null layout
    fmain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Close when X is clicked

    // controls and portions of Calendar
    lmonth = new JLabel("January");
    lyear = new JLabel("Change year:");
    cyear = new JComboBox();
    prev = new JButton("<<");
    next = new JButton(">>");
    canc = new JButton("Cancel");
    mcal =
        new DefaultTableModel() {
          public boolean isCellEditable(int rowIndex, int mColIndex) {
            return false;
          }
        };
    Cal = new JTable(mcal);
    scal = new JScrollPane(Cal);
    pcal = new JPanel(null);

    canc.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        });

    // action listeners for buttons and the like
    prev.addActionListener(new btnPrev_Action());
    next.addActionListener(new btnNext_Action());
    cyear.addActionListener(new cmbYear_Action());
    Cal.addMouseListener(new mouseCont());

    // Adding the elements to the pane
    pane.add(pcal);
    pcal.add(lmonth);
    pcal.add(cyear);
    pcal.add(prev);
    pcal.add(next);
    pcal.add(canc);
    pcal.add(scal);

    // Setting where the elements are on the pane
    pcal.setBounds(0, 0, 320, 335);
    lmonth.setBounds(160 - lmonth.getPreferredSize().width / 2, 25, 100, 25);
    canc.setBounds(10, 305, 80, 20);
    cyear.setBounds(215, 305, 100, 20);
    prev.setBounds(10, 25, 50, 25);
    next.setBounds(260, 25, 50, 25);
    scal.setBounds(10, 50, 300, 250);

    // Make frame visible
    fmain.setResizable(false);
    fmain.setVisible(true);

    // Inner workings for the day mechanism
    GregorianCalendar cal = new GregorianCalendar(); // Create calendar
    rday = cal.get(GregorianCalendar.DAY_OF_MONTH); // Get day
    rmonth = cal.get(GregorianCalendar.MONTH); // Get month
    ryear = cal.get(GregorianCalendar.YEAR); // Get year
    currentMonth = rmonth; // Match month and year
    currentYear = ryear;

    // Add days
    String[] days = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; // All of the days
    for (int i = 0; i < 7; i++) {
      mcal.addColumn(days[i]);
    }

    Cal.getParent().setBackground(Cal.getBackground()); // Set background

    // No resize/reorder
    Cal.getTableHeader().setResizingAllowed(false);
    Cal.getTableHeader().setReorderingAllowed(false);

    // Single cell selection
    Cal.setColumnSelectionAllowed(true);
    Cal.setRowSelectionAllowed(true);
    Cal.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // Set row/column count
    Cal.setRowHeight(38);
    mcal.setColumnCount(7);
    mcal.setRowCount(6);

    // Placing the dates in the cells
    for (int i = ryear - 100; i <= ryear + 100; i++) {
      cyear.addItem(String.valueOf(i));
    }

    // Refresh calendar
    refreshCalendar(rmonth, ryear); // Refresh calendar
  }