private void createUIComponents() {
    mainPanel = new DollarPanel();

    graphicOfPayments = new JTable();
    JTableHeader header = graphicOfPayments.getTableHeader();
    header.setPreferredSize(new Dimension(graphicOfPayments.getWidth(), HEADERS_HEIGHT));
  }
Ejemplo n.º 2
0
  /** Create the frame. */
  public SearchTable() {
    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowActivated(WindowEvent e) {
            do_this_windowActivated(e);
          }
        });
    setTitle("\u652F\u6301\u67E5\u627E\u529F\u80FD\u7684\u8868\u683C");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    JPanel panel = new JPanel();
    contentPane.add(panel, BorderLayout.NORTH);

    JLabel label = new JLabel("\u5173\u952E\u5B57\uFF1A");
    label.setFont(new Font("微软雅黑", Font.PLAIN, 16));
    panel.add(label);

    textField = new JTextField();
    textField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
    panel.add(textField);
    textField.setColumns(20);

    JPanel buttonPanel = new JPanel();
    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    JButton button = new JButton("\u67E5\u627E");
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            do_button_actionPerformed(e);
          }
        });
    button.setFont(new Font("微软雅黑", Font.PLAIN, 16));
    buttonPanel.add(button);

    JScrollPane scrollPane = new JScrollPane();
    contentPane.add(scrollPane, BorderLayout.CENTER);

    table = new JTable();
    table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
    table.setRowHeight(30);
    JTableHeader header = table.getTableHeader();
    header.setFont(new Font("微软雅黑", Font.PLAIN, 16));
    header.setPreferredSize(new Dimension(header.getWidth(), 35));
    scrollPane.setViewportView(table);
  }
Ejemplo n.º 3
0
  private void initTable() {
    JTableHeader header = table.getTableHeader();
    table.setRowHeight(ROW_HEIGHT);
    table.setFont(font);

    header.setFont(font);
    header.setPreferredSize(new Dimension(header.getWidth(), ROW_HEIGHT));

    table.setCellSelectionEnabled(false);
    table.setOpaque(false);
    //		table.setShowGrid(false);
    //		table.setShowVerticalLines(false);
    table.setGridColor(gridColor);

    // 设置表格颜色
    setForeground(foreColor);
    header.setForeground(foreColor);
    //		header.setBackground(headerColor);
    header.setBorder(new LineBorder(gridColor, 1));

    DefaultTableCellRenderer dtr =
        new DefaultTableCellRenderer() {
          private static final long serialVersionUID = 1L;

          @Override
          public Component getTableCellRendererComponent(
              JTable table,
              Object value,
              boolean isSelected,
              boolean hasFocus,
              int row,
              int column) {
            if (row % 2 == 0) {
              setBackground(backColor1);
            } else if (row % 2 == 1) {
              setBackground(backColor2);
            } else setBackground(backColor2);
            setForeground(foreColor);

            return super.getTableCellRendererComponent(
                table, value, isSelected, hasFocus, row, column);
          }
        };
    dtr.setHorizontalAlignment(JLabel.CENTER);
    for (int i = 0; i < headerStr.length; i++) {
      table.getColumn(headerStr[i]).setCellRenderer(dtr);
    }
    header.setDefaultRenderer(dtr);
  }
  /**
   * Updates the column header component in the scroll pane. This depends on the current results
   * view and whether the sponsored results are visible.
   */
  private void syncColumnHeader() {
    Component resultHeader = resultsContainer.getScrollPaneHeader();
    if (resultHeader == null) {
      // If no headers, use nothing special.
      scrollPane.setColumnHeaderView(null);
    } else if (!sponsoredResultsPanel.isVisible()) {
      // If sponsored results aren't visible, just use the actual header.
      scrollPane.setColumnHeaderView(resultHeader);
    } else {
      // Otherwise, create a combined panel that has both sponsored results & header.
      JXPanel headerPanel = new JXPanel();
      // Make sure this syncs with the layout for the results & sponsored results!
      headerPanel.setLayout(new MigLayout("hidemode 3, gap 0, insets 0", "[]", "[grow][]"));
      headerPanel.add(resultHeader, "grow, push, alignx left, aligny top");

      DefaultTableColumnModel model = new DefaultTableColumnModel();
      TableColumn column = new TableColumn();
      model.addColumn(column);
      JTableHeader header = new JTableHeader(model);
      header.setDefaultRenderer(new TableCellHeaderRenderer());
      header.setReorderingAllowed(false);
      header.setResizingAllowed(false);
      header.setTable(new JXTable(0, 1));

      int width = sponsoredResultsPanel.getPreferredSize().width;
      int height = resultHeader.getPreferredSize().height;
      column.setWidth(width);
      Dimension dimension = new Dimension(width, height);
      header.setPreferredSize(dimension);
      header.setMaximumSize(dimension);
      header.setMinimumSize(dimension);

      headerPanel.add(header, "aligny top, alignx right");
      scrollPane.setColumnHeaderView(headerPanel);
    }

    scrollPane.validate();

    // Resize and repaint table header.  This eliminates visual issues due
    // to a change in the table format, which can result in an incorrect
    // header height or header flickering when a category is selected.
    if (resultHeader instanceof JTableHeader) {
      ((JTableHeader) resultHeader).resizeAndRepaint();
    }
  }
Ejemplo n.º 5
0
 public void setRowHeight(int h) {
   this.ROW_HEIGHT = h;
   table.setRowHeight(ROW_HEIGHT);
   JTableHeader header = table.getTableHeader();
   header.setPreferredSize(new Dimension(header.getWidth(), ROW_HEIGHT));
 }