コード例 #1
0
 private static void setupTable(JTable table, Project project) {
   new TableSpeedSearch(table);
   table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   table.addMouseListener(new MetricTableMouseListener(project, table));
   final JTableHeader tableHeader = table.getTableHeader();
   tableHeader.addMouseListener(new MetricTableHeaderMouseListener(project, table));
 }
コード例 #2
0
  private void createUIComponents() {
    mainPanel = new DollarPanel();

    graphicOfPayments = new JTable();
    JTableHeader header = graphicOfPayments.getTableHeader();
    header.setPreferredSize(new Dimension(graphicOfPayments.getWidth(), HEADERS_HEIGHT));
  }
コード例 #3
0
  public void testEmptyHeader() {
    fFrame = new JFrame("Test Window");

    // Create a panel to hold all other components
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());

    // Create a new table instance
    MyTableModel myModel = new MyTableModel();
    fTable = new JTable(myModel);

    // Add the table to a scrolling pane
    JScrollPane scrollPane = new JScrollPane(fTable);
    topPanel.add(scrollPane, BorderLayout.CENTER);

    fFrame.getContentPane().setLayout(new BorderLayout());
    fFrame.getContentPane().add(BorderLayout.CENTER, topPanel);

    fFrame.setSize(400, 450);
    fFrame.setLocation(20, 20);
    fFrame.setVisible(true);
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    JTableHeader header = fTable.getTableHeader();
    assertTrue(
        "JTableHeader greater than 5 pixels tall with empty string first element.",
        header.getSize().height > 5);
    fFrame.setVisible(false);
    fFrame.dispose();
  }
コード例 #4
0
ファイル: Panel_Rooms.java プロジェクト: MKD225/hotellinuxdp
  @SuppressWarnings("unchecked")
  private JComponent jRoom() {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.setBorder(BorderFactory.createTitledBorder(""));
    scrollPane = new JScrollPane();
    jRoom = new JTable();
    tableTitle.add("RoomID");
    tableTitle.add("RoomNumber");
    tableTitle.add("RoomType");
    tableTitle.add("NumBeds");
    tableTitle.add("RoomTypeRate");
    tableTitle.add("RoomStatus");
    tableTitle.add("Description");

    model =
        new DefaultTableModel(tableRecords, tableTitle) {
          private static final long serialVersionUID = 1L;

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

    jRoom.setModel(model);
    jRoom.getTableHeader().setReorderingAllowed(false);
    scrollPane.setViewportView(jRoom);
    panel.add(scrollPane);

    return panel;
  }
コード例 #5
0
  public CombatViewer() {
    super("Combat Tracker");
    setLookAndFeel();
    setSize(500, 400);
    FlowLayout layout = new FlowLayout(FlowLayout.CENTER, 10, 10);
    setLayout(layout);

    String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};

    Object[][] data = {
      {"Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false)},
      {"John", "Doe", "Rowing", new Integer(3), new Boolean(true)},
      {"Sue", "Black", "Knitting", new Integer(2), new Boolean(false)},
      {"Jane", "White", "Speed reading", new Integer(20), new Boolean(true)},
      {"Joe", "Brown", "Pool", new Integer(10), new Boolean(false)}
    };

    JTable table = new JTable(data, columnNames);

    JScrollPane scrollPane = new JScrollPane(table);
    table.setFillsViewportHeight(true);

    panel1.setLayout(new BorderLayout());
    panel1.add(table.getTableHeader(), BorderLayout.PAGE_START);
    panel1.add(table, BorderLayout.CENTER);
    add(panel1);

    panel2.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
    panel2.add(testBox);
    add(panel2);

    setVisible(true);
  }
コード例 #6
0
  public JointPriorDialog(JFrame frame, BeautiOptions options) {
    this.frame = frame;

    this.options = options;

    priorSettingsPanel = new PriorSettingsPanel(frame);

    nameField.setColumns(30);

    parametersTableModel = new ParametersTableModel();
    //        TableSorter sorter = new TableSorter(traitsTableModel);
    //        traitsTable = new JTable(sorter);
    //        sorter.setTableHeader(traitsTable.getTableHeader());
    parametersTable = new JTable(parametersTableModel);

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

    parametersTable
        .getSelectionModel()
        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    parametersTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent evt) {
                parametersSelectionChanged();
              }
            });
  }
コード例 #7
0
  public static void main(String args[]) {
    File[] IFCFiles = new File("D:\\Data\\Emiel\\CreateTable\\IFC").listFiles();
    File[] XMLFiles = new File("D:\\Data\\Emiel\\CreateTable\\XML").listFiles();
    Object[] col = new Object[IFCFiles.length + 1];
    Object[][] dat = new Object[XMLFiles.length][IFCFiles.length + 1];
    col[0] = " ";
    for (int j = 0; j < IFCFiles.length; j++) {
      col[j + 1] = IFCFiles[j].getName();

      for (int i = 0; i < XMLFiles.length; i++) {
        File[] BCFFiles =
            new File(
                    "D:\\Data\\Emiel\\CreateTable\\Results\\"
                        + IFCFiles[j].getName()
                        + "\\"
                        + XMLFiles[i].getName())
                .listFiles();
        System.out.println(BCFFiles.length);

        dat[i][0] = XMLFiles[i].getName();
        dat[i][j + 1] = BCFFiles.length;
      }
    }

    JFrame frame = new JFrame("MVD Checker");
    JTable table = new JTable(dat, col);
    frame.setVisible(true);
    frame.setBounds(0, 0, 500, 500);
    frame.add(table.getTableHeader(), BorderLayout.PAGE_START);
    frame.add(table);
  }
コード例 #8
0
ファイル: LookSpike.java プロジェクト: fcuenca/lets_play_tdd
  // This method from http://www.exampledepot.com/egs/javax.swing.table/PackCol.html
  public int packColumn(JTable table, int vColIndex, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width = 0;

    // Get width of column header
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
      renderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp =
        renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;

    // Get maximum width of column data
    for (int r = 0; r < table.getRowCount(); r++) {
      renderer = table.getCellRenderer(r, vColIndex);
      comp =
          renderer.getTableCellRendererComponent(
              table, table.getValueAt(r, vColIndex), false, false, r, vColIndex);
      width = Math.max(width, comp.getPreferredSize().width);
    }

    // Add margin
    width += 2 * margin;

    // Set the width
    col.setPreferredWidth(width);

    return width;
  }
コード例 #9
0
    public ReplicatedTreeView(ReplicatedTree tree, Object title) throws Exception {
      this.tree = tree;
      tree.addReplicatedTreeListener(this);

      addNotify();
      setTitle("ReplicatedTreeDemo: mbr=" + title);

      tree_model = new DefaultTreeModel(root);
      jtree = new JTree(tree_model);
      jtree.setDoubleBuffered(true);
      jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

      JScrollPane scroll_pane = new JScrollPane(jtree);

      populateTree();

      getContentPane().add(scroll_pane, BorderLayout.CENTER);
      addWindowListener(this);

      table_model.setColumnIdentifiers(new String[] {"Name", "Value"});
      table_model.addTableModelListener(this);

      setTableColumnWidths();

      tablePanel = new JPanel();
      tablePanel.setLayout(new BorderLayout());
      tablePanel.add(table.getTableHeader(), BorderLayout.NORTH);
      tablePanel.add(table, BorderLayout.CENTER);

      getContentPane().add(tablePanel, BorderLayout.SOUTH);

      jtree.addTreeSelectionListener(this); // REVISIT

      MouseListener ml =
          new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              int selRow = jtree.getRowForLocation(e.getX(), e.getY());
              TreePath selPath = jtree.getPathForLocation(e.getX(), e.getY());
              if (selRow != -1) {
                selected_node = makeFQN(selPath.getPath());
                jtree.setSelectionPath(selPath);

                if (e.getModifiers() == java.awt.event.InputEvent.BUTTON3_MASK) {
                  operationsPopup.show(e.getComponent(), e.getX(), e.getY());
                }
              }
            }
          };

      jtree.addMouseListener(ml);

      createMenus();
      setLocation(50, 50);
      setSize(
          getInsets().left + getInsets().right + 485, getInsets().top + getInsets().bottom + 367);

      init();
      setVisible(true);
    }
 private int getColumnHeaderWidth(JTable table, int colIndex) {
   TableColumn col = table.getColumnModel().getColumn(colIndex);
   TableCellRenderer renderer = col.getHeaderRenderer();
   if (renderer == null) renderer = table.getTableHeader().getDefaultRenderer();
   Component comp =
       renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
   return comp.getPreferredSize().width;
 }
コード例 #11
0
  /**
   * This method restores the width of the specified column to its previous width.
   *
   * @param column The column to restore.
   */
  private void restoreColumn(int column) {
    TableColumn tableColumn = table.getColumnModel().getColumn(column);
    Integer width = columnSizes.get(tableColumn);

    if (width != null) {
      table.getTableHeader().setResizingColumn(tableColumn);
      tableColumn.setWidth(width.intValue());
    }
  }
コード例 #12
0
 public HistoryViewImpl() {
   super(500, 475);
   add(table.getTableHeader(), PAGE_START);
   add(table, CENTER);
   add(applyButton, BorderLayout.SOUTH);
   add(shareButton, BorderLayout.SOUTH);
   addApplyButtonClickedListener();
   addShareButtonClickedListener();
 }
コード例 #13
0
 RowHeaderRenderer(JTable table) {
   JTableHeader header = table.getTableHeader();
   setOpaque(true);
   setBorder(UIManager.getBorder("TableHeader.cellBorder"));
   setHorizontalAlignment(CENTER);
   setForeground(header.getForeground());
   setBackground(header.getBackground());
   setFont(header.getFont());
 }
コード例 #14
0
  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);
  }
コード例 #15
0
ファイル: BaseScoreDialog.java プロジェクト: programus/j-bots
 /**
  * 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;
 }
コード例 #16
0
  private String extractContent(
      DataGridPanel grid, String delimiter, boolean saveHeader, boolean ecloseWithDowbleQuotes) {
    JTable _table = grid.getTable();

    int numcols = _table.getSelectedColumnCount();
    int numrows = _table.getSelectedRowCount();

    if (numcols > 0 && numrows > 0) {
      StringBuffer sbf = new StringBuffer();
      int[] rowsselected = _table.getSelectedRows();
      int[] colsselected = _table.getSelectedColumns();

      if (saveHeader) {
        // put header name list
        for (int j = 0; j < numcols; j++) {
          String text =
              (String)
                  _table
                      .getTableHeader()
                      .getColumnModel()
                      .getColumn(colsselected[j])
                      .getHeaderValue();
          sbf.append(text);
          if (j < numcols - 1) sbf.append(delimiter);
        }
        sbf.append("\n");
      }

      // put content
      for (int i = 0; i < numrows; i++) {
        for (int j = 0; j < numcols; j++) {
          Object value = _table.getValueAt(rowsselected[i], colsselected[j]);
          String _value = "";
          if (value != null) {
            _value = value.toString();
          }
          if (ecloseWithDowbleQuotes) {
            sbf.append("\"").append(_value).append("\"");
          } else {
            sbf.append(_value);
          }

          if (j < numcols - 1) sbf.append(delimiter);
        }
        sbf.append("\n");
      }

      //            StringSelection stsel = new StringSelection(sbf.toString());
      //            Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
      //            system.setContents(stsel, stsel);
      return sbf.toString();
    }

    return null;
  }
コード例 #17
0
  public AppointmentGUI() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setBounds(100, 100, 500, 600); // window size
    setTitle("Appointment List"); // window title
    contentPane = new JPanel();
    contentPane.setBorder(
        new EmptyBorder(3, 6, 3, 6)); // distance the plane is from the edges of the window
    setContentPane(contentPane);
    contentPane.setLayout(new BorderLayout(0, 0));
    scrollPane = new JScrollPane();
    contentPane.add(scrollPane, BorderLayout.CENTER);

    table =
        new JTable(
            new DefaultTableModel(new Object[] {"Doctor's Name", "Location", "Date", "Time"}, 60)) {
          public boolean isCellEditable(
              int row,
              int column) { // prevents user from editing cells; there apparently is not a cleaner
            // way of doing this
            return false;
          }
        };
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);
    table.setShowGrid(false);
    table.getTableHeader().setReorderingAllowed(false); // prevent user from swapping columns
    table.getTableHeader().setResizingAllowed(false); // prevent user from resizing columns
    table.setSelectionMode(
        ListSelectionModel
            .SINGLE_INTERVAL_SELECTION); // prevent user from selecting multiple doctors
    table.setAutoCreateColumnsFromModel(
        false); // forgot why I have this here; it's probably important

    scrollPane.setViewportView(table); // lets table be scroll able

    btnPane = new JPanel();
    btnPane.setLayout(new GridLayout(0, 2, 0, 0));
    contentPane.add(btnPane, BorderLayout.SOUTH);

    btnViewAppointment = new JButton("View Appointment");
    btnPane.add(btnViewAppointment);

    btnCancelAppointment = new JButton("Cancel Appointment");
    btnPane.add(btnCancelAppointment);

    btnUpdateAppointment = new JButton("Update Appointment");
    btnPane.add(btnUpdateAppointment);

    btnGoBack = new JButton("Go Back");
    btnPane.add(btnGoBack);
  }
コード例 #18
0
  /*
   *  Calculated the width based on the column name
   */
  private int getColumnHeaderWidth(int column) {
    if (!isColumnHeaderIncluded) return 0;

    TableColumn tableColumn = table.getColumnModel().getColumn(column);
    Object value = tableColumn.getHeaderValue();
    TableCellRenderer renderer = tableColumn.getHeaderRenderer();

    if (renderer == null) {
      renderer = table.getTableHeader().getDefaultRenderer();
    }

    Component c = renderer.getTableCellRendererComponent(table, value, false, false, -1, column);
    return c.getPreferredSize().width;
  }
コード例 #19
0
  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);
  }
コード例 #20
0
    public Component getTableCellRendererComponent(
        JTable table,
        Object value,
        boolean selected,
        boolean hasFocus,
        int rowIndex,
        int columnIndex) {
      Component component =
          super.getTableCellRendererComponent(
              table, value, selected, hasFocus, rowIndex, columnIndex);

      if (!selected) component.setBackground(table.getTableHeader().getBackground());

      return component;
    }
コード例 #21
0
  /**
   * Sets whether or not this component is enabled. Disabling this pane will
   * also disable its children.
   *
   * @param enabled <code>true<code> if this component and its children should
   * be enabled, <code>false<code> otherwise
   */
  public void setEnabled(boolean enabled) {
    super.setEnabled(enabled);

    addButton.setEnabled(enabled);
    table.setEnabled(enabled);
    table.getTableHeader().setEnabled(enabled);

    if (enabled) {
      editButton.setEnabled(selectionModel.getSelectedValues().length == 1);
      removeButton.setEnabled(!selectionModel.isSelectionEmpty());
    } else {
      table.clearSelection();

      editButton.setEnabled(enabled);
      removeButton.setEnabled(enabled);
    }
  }
コード例 #22
0
  /*
   *  Update the TableColumn with the newly calculated width
   */
  private void updateTableColumn(int column, int width) {
    final TableColumn tableColumn = table.getColumnModel().getColumn(column);

    if (!tableColumn.getResizable()) return;

    width += spacing;

    //  Don't shrink the column width

    if (isOnlyAdjustLarger) {
      width = Math.max(width, tableColumn.getPreferredWidth());
    }

    columnSizes.put(tableColumn, new Integer(tableColumn.getWidth()));
    table.getTableHeader().setResizingColumn(tableColumn);
    tableColumn.setWidth(width);
  }
コード例 #23
0
    public Component getTableCellRendererComponent(
        JTable headerTable,
        Object value,
        boolean isSelected,
        boolean hasFocus,
        int row,
        int column) {

      TableCellRenderer r = table.getTableHeader().getDefaultRenderer();

      JLabel c =
          (JLabel)
              r.getTableCellRendererComponent(headerTable, value, isSelected, hasFocus, row, 0);
      c.setHorizontalAlignment(SwingConstants.RIGHT);
      c.setVerticalAlignment(SwingConstants.TOP);
      return c;
    }
コード例 #24
0
    public void mouseClicked(MouseEvent e) {
      TableColumnModel colModel = table.getColumnModel();
      int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
      int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();

      if (modelIndex < 0) return;
      if (sortCol == modelIndex) isSortAsc = !isSortAsc;
      else sortCol = modelIndex;

      for (int i = 0; i < colNames.length; i++) {
        TableColumn column = colModel.getColumn(i);
        column.setHeaderValue(getColumnName(column.getModelIndex()));
      }
      table.getTableHeader().repaint();

      Collections.sort(rowData, new MyComparator(isSortAsc));
      table.tableChanged(new TableModelEvent(MyTableModel.this));
      table.repaint();
    }
コード例 #25
0
ファイル: BaseScoreDialog.java プロジェクト: programus/j-bots
  /**
   * Return the scroll pane
   *
   * @return JScrollPane
   */
  protected JScrollPane getScrollPane() {
    if (scrollPane == null) {
      scrollPane = new JScrollPane();
      scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
      scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      scrollPane.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE);
      scrollPane.setViewportView(getTable());
      scrollPane.setColumnHeaderView(table.getTableHeader());
      scrollPane.addComponentListener(eventHandler);

      tableSize =
          new Dimension(
              getTable().getColumnModel().getTotalColumnWidth(),
              getTable().getModel().getRowCount() * (getTable().getRowHeight()));
      table.setPreferredScrollableViewportSize(tableSize);
      table.setPreferredSize(tableSize);
      table.setMinimumSize(tableSize);
    }
    return scrollPane;
  }
コード例 #26
0
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      if (table != null) {
        JTableHeader header = table.getTableHeader();
        if (header != null) {
          setFont(header.getFont());
        }
      }
      this.isSelected = isSelected;
      this.hasFocus = hasFocus;
      this.column = column;
      this.hasRollover = (column == rolloverColumn);
      if (skin == null || skin.getContentMargin() == null) {
        skin = XPStyle.getXP().getSkin(header, "header.headeritem");
      }
      setText((value == null) ? "" : value.toString());
      setBorder(new EmptyBorder(skin.getContentMargin()));

      return this;
    }
コード例 #27
0
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      if (table != null) {
        JTableHeader header = table.getTableHeader();

        if (header != null) {
          setForeground(header.getForeground());
          setBackground(header.getBackground());
          setFont(header.getFont());
        }
      }

      if (isSelected) {
        setFont(getFont().deriveFont(Font.BOLD));
      }

      setText((value == null) ? "" : value.toString());
      setBorder(UIManager.getBorder("TableHeader.cellBorder"));

      return this;
    }
コード例 #28
0
  GroupableHeaderExample() {
    super("Groupable Header Example");

    DefaultTableModel dm = new DefaultTableModel();
    dm.setDataVector(
        new Object[][] {
          {"119", "foo", "bar", "ja", "ko", "zh"},
          {"911", "bar", "foo", "en", "fr", "pt"}
        },
        new Object[] {"SNo.", "1", "2", "Native", "2", "3"});

    JTable table =
        new JTable(dm) {
          protected JTableHeader createDefaultTableHeader() {
            return new GroupableTableHeader(columnModel);
          }
        };

    TableColumnModel cm = table.getColumnModel();
    ColumnGroup g_name = new ColumnGroup("Name");
    g_name.add(cm.getColumn(1));
    g_name.add(cm.getColumn(2));
    ColumnGroup g_lang = new ColumnGroup("Language");
    g_lang.add(cm.getColumn(3));
    ColumnGroup g_other = new ColumnGroup("Others");
    g_other.add(cm.getColumn(4));
    g_other.add(cm.getColumn(5));
    g_lang.add(g_other);

    GroupableTableHeader header = (GroupableTableHeader) table.getTableHeader();
    header.addColumnGroup(g_name);
    header.addColumnGroup(g_lang);
    JScrollPane scroll = new JScrollPane(table);
    getContentPane().add(scroll);
    setSize(400, 120);
  }
コード例 #29
0
  public FixedColumnExample() {
    super("Fixed Column Example");
    setSize(400, 150);
    data =
        new Object[][] {
          {"1", "11", "A", "", "", "", "", ""},
          {"2", "22", "", "B", "", "", "", ""},
          {"3", "33", "", "", "C", "", "", ""},
          {"4", "44", "", "", "", "D", "", ""},
          {"5", "55", "", "", "", "", "E", ""},
          {"6", "66", "", "", "", "", "", "F"}
        };
    column = new Object[] {"fixed 1", "fixed 2", "a", "b", "c", "d", "e", "f"};
    AbstractTableModel fixedModel =
        new AbstractTableModel() {
          public int getColumnCount() {
            return 2;
          }

          public int getRowCount() {
            return data.length;
          }

          public String getColumnName(int col) {
            return (String) column[col];
          }

          public Object getValueAt(int row, int col) {
            return data[row][col];
          }
        };
    AbstractTableModel model =
        new AbstractTableModel() {
          public int getColumnCount() {
            return column.length - 2;
          }

          public int getRowCount() {
            return data.length;
          }

          public String getColumnName(int col) {
            return (String) column[col + 2];
          }

          public Object getValueAt(int row, int col) {
            return data[row][col + 2];
          }

          public void setValueAt(Object obj, int row, int col) {
            data[row][col + 2] = obj;
          }

          public boolean CellEditable(int row, int col) {
            return true;
          }
        };
    fixedTable =
        new JTable(fixedModel) {
          public void valueChanged(ListSelectionEvent e) {
            super.valueChanged(e);
            checkSelection(true);
          }
        };
    table =
        new JTable(model) {
          public void valueChanged(ListSelectionEvent e) {
            super.valueChanged(e);
            checkSelection(false);
          }
        };
    fixedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    fixedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane scroll = new JScrollPane(table);
    JViewport viewport = new JViewport();
    viewport.setView(fixedTable);
    viewport.setPreferredSize(fixedTable.getPreferredSize());
    scroll.setRowHeaderView(viewport);
    scroll.setCorner(JScrollPane.UPPER_LEFT_CORNER, fixedTable.getTableHeader());
    getContentPane().add(scroll, BorderLayout.CENTER);
  }
コード例 #30
0
  private void addBasicPanels() {
    JSplitPane allPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    allPane.setOneTouchExpandable(true);

    messagesTable =
        new DefaultTableModel(
            new Object[] {"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"}, 0) {
          private static final long serialVersionUID = 8136121224474217264L;

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

          public Class<?> getColumnClass(int columnIndex) {
            if (columnIndex == 2 || columnIndex == 3) {
              return Icon.class;
            }
            return super.getColumnClass(columnIndex);
          }
        };
    JTable table = new JTable(messagesTable);
    // Allow only single a selection
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // Hide the first column
    table.getColumnModel().getColumn(0).setMaxWidth(0);
    table.getColumnModel().getColumn(0).setMinWidth(0);
    table.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
    table.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
    // Set the column "timestamp" size
    table.getColumnModel().getColumn(1).setMaxWidth(300);
    table.getColumnModel().getColumn(1).setPreferredWidth(90);
    // Set the column "direction" icon size
    table.getColumnModel().getColumn(2).setMaxWidth(50);
    table.getColumnModel().getColumn(2).setPreferredWidth(30);
    // Set the column "packet type" icon size
    table.getColumnModel().getColumn(3).setMaxWidth(50);
    table.getColumnModel().getColumn(3).setPreferredWidth(30);
    // Set the column "Id" size
    table.getColumnModel().getColumn(5).setMaxWidth(100);
    table.getColumnModel().getColumn(5).setPreferredWidth(55);
    // Set the column "type" size
    table.getColumnModel().getColumn(6).setMaxWidth(200);
    table.getColumnModel().getColumn(6).setPreferredWidth(50);
    // Set the column "to" size
    table.getColumnModel().getColumn(7).setMaxWidth(300);
    table.getColumnModel().getColumn(7).setPreferredWidth(90);
    // Set the column "from" size
    table.getColumnModel().getColumn(8).setMaxWidth(300);
    table.getColumnModel().getColumn(8).setPreferredWidth(90);
    // Create a table listener that listen for row selection events
    SelectionListener selectionListener = new SelectionListener(table);
    table.getSelectionModel().addListSelectionListener(selectionListener);
    table.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener);
    allPane.setTopComponent(new JScrollPane(table));
    messageTextArea = new JTextArea();
    messageTextArea.setEditable(false);
    // Add pop-up menu.
    JPopupMenu menu = new JPopupMenu();
    JMenuItem menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(messageTextArea.getText()), null);
          }
        });
    menu.add(menuItem1);
    // Add listener to the text area so the popup menu can come up.
    messageTextArea.addMouseListener(new PopupListener(menu));
    JPanel sublayout = new JPanel(new BorderLayout());
    sublayout.add(new JScrollPane(messageTextArea), BorderLayout.CENTER);

    JButton clearb = new JButton("Clear All Packets");

    clearb.addActionListener(
        new AbstractAction() {
          private static final long serialVersionUID = -8576045822764763613L;

          @Override
          public void actionPerformed(ActionEvent e) {
            messagesTable.setRowCount(0);
          }
        });

    sublayout.add(clearb, BorderLayout.NORTH);
    allPane.setBottomComponent(sublayout);

    allPane.setDividerLocation(150);

    tabbedPane.add("All Packets", allPane);
    tabbedPane.setToolTipTextAt(0, "Sent and received packets processed by Smack");

    // Create UI elements for client generated XML traffic.
    final JTextArea sentText = new JTextArea();
    sentText.setWrapStyleWord(true);
    sentText.setLineWrap(true);
    sentText.setEditable(false);
    sentText.setForeground(new Color(112, 3, 3));
    tabbedPane.add("Raw Sent Packets", new JScrollPane(sentText));
    tabbedPane.setToolTipTextAt(1, "Raw text of the sent packets");

    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(sentText.getText()), null);
          }
        });

    JMenuItem menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            sentText.setText("");
          }
        });

    // Add listener to the text area so the popup menu can come up.
    sentText.addMouseListener(new PopupListener(menu));
    menu.add(menuItem1);
    menu.add(menuItem2);

    // Create UI elements for server generated XML traffic.
    final JTextArea receivedText = new JTextArea();
    receivedText.setWrapStyleWord(true);
    receivedText.setLineWrap(true);
    receivedText.setEditable(false);
    receivedText.setForeground(new Color(6, 76, 133));
    tabbedPane.add("Raw Received Packets", new JScrollPane(receivedText));
    tabbedPane.setToolTipTextAt(2, "Raw text of the received packets before Smack process them");

    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(receivedText.getText()), null);
          }
        });

    menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            receivedText.setText("");
          }
        });

    // Add listener to the text area so the popup menu can come up.
    receivedText.addMouseListener(new PopupListener(menu));
    menu.add(menuItem1);
    menu.add(menuItem2);

    // Create a special Reader that wraps the main Reader and logs data to the GUI.
    ObservableReader debugReader = new ObservableReader(reader);
    readerListener =
        new ReaderListener() {
          public void read(final String str) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER
                        && !EnhancedDebuggerWindow.getInstance().isVisible()) {
                      // Do not add content if the parent is not visible
                      return;
                    }

                    int index = str.lastIndexOf(">");
                    if (index != -1) {
                      if (receivedText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
                        try {
                          receivedText.replaceRange("", 0, receivedText.getLineEndOffset(0));
                        } catch (BadLocationException e) {
                          e.printStackTrace();
                        }
                      }
                      receivedText.append(str.substring(0, index + 1));
                      receivedText.append(NEWLINE);
                      if (str.length() > index) {
                        receivedText.append(str.substring(index + 1));
                      }
                    } else {
                      receivedText.append(str);
                    }
                  }
                });
          }
        };
    debugReader.addReaderListener(readerListener);

    // Create a special Writer that wraps the main Writer and logs data to the GUI.
    ObservableWriter debugWriter = new ObservableWriter(writer);
    writerListener =
        new WriterListener() {
          public void write(final String str) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER
                        && !EnhancedDebuggerWindow.getInstance().isVisible()) {
                      // Do not add content if the parent is not visible
                      return;
                    }

                    if (sentText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
                      try {
                        sentText.replaceRange("", 0, sentText.getLineEndOffset(0));
                      } catch (BadLocationException e) {
                        e.printStackTrace();
                      }
                    }

                    sentText.append(str);
                    if (str.endsWith(">")) {
                      sentText.append(NEWLINE);
                    }
                  }
                });
          }
        };
    debugWriter.addWriterListener(writerListener);

    // Assign the reader/writer objects to use the debug versions. The packet reader
    // and writer will use the debug versions when they are created.
    reader = debugReader;
    writer = debugWriter;
  }