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);
  }
  public CustomLeagueTable(String teamAmount) {

    model = new DefaultTableModel();
    table =
        new JTable(model) {
          @Override
          public boolean isCellEditable(int row, int column) {
            return true;
          }
        };
    model.setColumnIdentifiers(
        new String[] {
          "Team Name", "Points", "Goal Diff", "Wins", "Loses", "Draws", "Played", "League Verdict"
        });
    model.setRowCount(Integer.parseInt(teamAmount));

    JScrollPane pane =
        new JScrollPane(
            table,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane.setPreferredSize(INITIAL_SIZE);
    setVisible(true);
    setLayout(new FlowLayout());

    table.setRowSelectionAllowed(false);

    TableColumn colTeamName = table.getColumnModel().getColumn(0);
    colTeamName.setPreferredWidth(150);

    TableColumn colVerdict = table.getColumnModel().getColumn(4);
    colVerdict.setPreferredWidth(290);

    add(pane);
  }
Пример #3
0
  // 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);
    }
  }
Пример #4
0
  private void init(final EncodeTableModel model) {
    setModal(true);
    setTitle("Encode Production Data");

    table.setAutoCreateRowSorter(true);
    table.setModel(model);
    table.setRowSorter(model.getSorter());
    try {
      rowCountLabel.setText(numberFormatter.valueToString(table.getRowCount()) + " rows");
    } catch (ParseException e) {

    }

    table.setRowSelectionAllowed(false);
    table.setColumnSelectionAllowed(false);

    filterTextField
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              public void changedUpdate(DocumentEvent e) {
                updateFilter();
              }

              public void insertUpdate(DocumentEvent e) {
                updateFilter();
              }

              public void removeUpdate(DocumentEvent e) {
                updateFilter();
              }
            });
  }
Пример #5
0
 /**
  * Return the table.
  *
  * @return JTable
  */
 protected JTable getTable() {
   if (table == null) {
     table = new JTable();
     table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
     table.setColumnSelectionAllowed(true);
     table.setRowSelectionAllowed(true);
     table.getTableHeader().setReorderingAllowed(false);
   }
   return table;
 }
Пример #6
0
  public void createviewPanel() {

    viewPanel = new JPanel();
    viewPanel.setLayout(new BorderLayout());
    // viewPanel.setPreferredSize( new Dimension(500,500 ));
    // viewPanel.setMinimumSize( new Dimension(100,50));
    // viewPanel.add( new JLabel("Notes:"),BorderLayout.NORTH );
    //		viewPanel.add( new JTextArea(), BorderLayout.CENTER );
    viewPanel.setPreferredSize(new Dimension(200, 520));
    viewPanel.setMinimumSize(new Dimension(100, 100));
    // Create columns
    CreateColumns(colcnt);
    CreateData(rowcnt, colcnt);
    setSize(300, 200);

    table =
        new JTable(dataValues, columnNames) {

          public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
          }
        };

    table
        .getModel()
        .addTableModelListener(
            new TableModelListener() {

              public void tableChanged(TableModelEvent e) {
                System.out.println("........" + e);
              }
            });
    // table.setValueAt("1,2",0,0);

    System.out.println("Row   :" + rowcnt);
    System.out.println("Col  :" + colcnt);

    // Configure some of JTable's paramters
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);
    table.setRowSelectionAllowed(false);
    table.setColumnSelectionAllowed(false);

    // Change the selection colour
    table.setSelectionForeground(Color.white);
    table.setSelectionBackground(Color.red);

    // Add the table to a scrolling pane
    scrollPaneTable = JTable.createScrollPaneForTable(table);
    viewPanel.add(scrollPaneTable, BorderLayout.CENTER);
    viewPanel.add(table, BorderLayout.CENTER);
  }
Пример #7
0
  private void loadView() {
    // main views
    mTableModel = new SpreadsheetTableModel();

    mTableView = new JTable(mTableModel);
    mTableView.setRowSelectionAllowed(false);
    mTableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    mTableView.setFillsViewportHeight(true);
    mTableView.setDefaultRenderer(String.class, new ColorCellRenderer(TABLE_CELL_COLOR));
    mTableView.setDefaultEditor(
        String.class, new SpreadsheetCellEditor(mTableView.getDefaultEditor(String.class)));
    mTableView.getSelectionModel().addListSelectionListener(new SpreadsheetSelectionListener());
    mTableView
        .getColumnModel()
        .getSelectionModel()
        .addListSelectionListener(new SpreadsheetSelectionListener());

    JTable rowHeaderTable = new JTable(new RowHeaderTableModel());
    rowHeaderTable.setCellSelectionEnabled(false);
    rowHeaderTable.setPreferredScrollableViewportSize(new Dimension(50, Integer.MAX_VALUE));
    rowHeaderTable.setDefaultRenderer(Object.class, new ColorCellRenderer(ROW_HEADER_COLOR));

    mFormulaTextField = new BindableTextField();
    mFormulaTextField.setEditable(false);
    mFormulaTextField.setFocusable(false);

    JScrollPane scrollView = new JScrollPane(mTableView);
    scrollView.setRowHeaderView(rowHeaderTable);

    add(mFormulaTextField, BorderLayout.BEFORE_FIRST_LINE);
    add(scrollView, BorderLayout.CENTER);

    // helpers

    mFileChooser = new SingleExtensionFileChooser();
    String extension = SpreadsheetPersistenceManager.SPREADSHEET_FILE_EXTENSION;
    mFileChooser.setFileExtension(extension, "Spreadsheets file (." + extension + ")");
  }
  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);
  }
Пример #9
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);
 }
  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);
            }
          }
        });
  }
  public AutoFocusator() {
    super(new BorderLayout());

    taskList = new TaskList();
    Task task0 = new Task("Use right click to change the states of the tasks.");
    taskList.add(task0);
    Task task1 = new Task("Just play araound with this small app.");
    taskList.add(task1);
    Task task2 = new Task("Check http://sourceforge.net/projects/autofocusator/");
    taskList.add(task2);

    // task1.setState(State.crossed);
    // task0.setState(State.dismissed);

    table = new JTable(taskList);
    table.setPreferredScrollableViewportSize(new Dimension(500, 700));
    table.setFillsViewportHeight(true);
    table.getColumnModel().getColumn(0).setPreferredWidth(300);
    table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    table.setRowSelectionAllowed(true);

    table.getColumnModel().getColumn(0).setCellRenderer(new TaskRenderer());
    // TableCellRenderer renderer = table.getColumnModel().getColumn(0).getCellRenderer();
    // double height = ((TaskRenderer)renderer).getRendererHeight();

    // @todo: The height should be set dependent on the content
    table.setRowHeight(28);

    table.getModel().addTableModelListener(this);

    toolBar = new JToolBar("Autofocusator - Toolbar");

    JButton buttonAddTask = new JButton("Add a Task", new ImageIcon(loadPics("res/list-add.png")));
    buttonAddTask.setActionCommand("addTask");
    buttonAddTask.addActionListener(this);
    toolBar.add(buttonAddTask);

    JButton buttonDeleteTask =
        new JButton("Delete a Task", new ImageIcon(loadPics("res/list-remove.png")));
    buttonDeleteTask.setActionCommand("deleteTask");
    buttonDeleteTask.addActionListener(this);
    toolBar.add(buttonDeleteTask);

    JButton buttonSave = new JButton("Save", new ImageIcon(loadPics("res/document-save-as.png")));
    buttonSave.setActionCommand("save");
    buttonSave.addActionListener(this);
    toolBar.add(buttonSave);

    JButton buttonOpen = new JButton("open", new ImageIcon(loadPics("res/document-open.png")));
    buttonOpen.setActionCommand("open");
    buttonOpen.addActionListener(this);
    toolBar.add(buttonOpen);

    add(toolBar, BorderLayout.NORTH);

    contextMenu = new JPopupMenu();
    JMenuItem contextMenuItem;
    contextMenuItem = new JMenuItem("delete Task");
    contextMenuItem.addActionListener(this);
    contextMenuItem.setActionCommand("deleteTask");
    contextMenu.add(contextMenuItem);

    contextMenuItem = new JMenuItem("add Task");
    contextMenuItem.addActionListener(this);
    contextMenuItem.setActionCommand("addTask");
    contextMenu.add(contextMenuItem);

    contextMenu.addSeparator();

    contextMenuItem = new JMenuItem("cross");
    contextMenuItem.addActionListener(this);
    contextMenuItem.setActionCommand("cross");
    contextMenu.add(contextMenuItem);

    contextMenuItem = new JMenuItem("dismiss");
    contextMenuItem.addActionListener(this);
    contextMenuItem.setActionCommand("dismiss");
    contextMenu.add(contextMenuItem);

    contextMenuItem = new JMenuItem("worked on");
    contextMenuItem.addActionListener(this);
    contextMenuItem.setActionCommand("workedOn");
    contextMenu.add(contextMenuItem);

    fileChooser = new JFileChooser();
    FileFilter filter = new FileNameExtensionFilter("XML File", "xml");
    fileChooser.addChoosableFileFilter(filter);

    table.addMouseListener(this);

    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane, BorderLayout.CENTER);
  }
Пример #12
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
  }