Exemple #1
0
 public static void main(String[] args) {
   /*
   构造函数有很多下面先介绍几个:
   JTable()
   JTable(int numRows, int numColumns)
   JTable(Object[][] rowData, Object[] columnNames)
   */
   JTable example1 = new JTable(); // 看不到但存在
   JTable example2 = new JTable(8, 6);
   final Object[] columnNames = {
     "姓名", "性别", "家庭地址", // 列名最好用final修饰
     "电话号码", "生日", "工作", "收入", "婚姻状况", "恋爱状况"
   };
   Object[][] rowData = {
     {"ddd", "男", "江苏南京", "1378313210", "03/24/1985", "学生", "寄生中", "未婚", "没"},
     {"eee", "女", "江苏南京", "13645181705", "xx/xx/1985", "家教", "未知", "未婚", "好象没"},
     {"fff", "男", "江苏南京", "13585331486", "12/08/1985", "汽车推销员", "不确定", "未婚", "有"},
     {"ggg", "女", "江苏南京", "81513779", "xx/xx/1986", "宾馆服务员", "确定但未知", "未婚", "有"},
     {"hhh", "男", "江苏南京", "13651545936", "xx/xx/1985", "学生", "流放中", "未婚", "无数次分手后没有"}
   };
   JTable friends = new JTable(rowData, columnNames);
   friends.setPreferredScrollableViewportSize(new Dimension(600, 100)); // 设置表格的大小
   friends.setRowHeight(30); // 设置每行的高度为20
   friends.setRowHeight(0, 20); // 设置第1行的高度为15
   friends.setRowMargin(5); // 设置相邻两行单元格的距离
   friends.setRowSelectionAllowed(true); // 设置可否被选择.默认为false
   friends.setSelectionBackground(Color.white); // 设置所选择行的背景色
   friends.setSelectionForeground(Color.red); // 设置所选择行的前景色
   friends.setGridColor(Color.black); // 设置网格线的颜色
   friends.selectAll(); // 选择所有行
   friends.setRowSelectionInterval(0, 2); // 设置初始的选择行,这里是1到3行都处于选择状态
   friends.clearSelection(); // 取消选择
   friends.setDragEnabled(false); // 不懂这个
   friends.setShowGrid(false); // 是否显示网格线
   friends.setShowHorizontalLines(false); // 是否显示水平的网格线
   friends.setShowVerticalLines(true); // 是否显示垂直的网格线
   friends.setValueAt("tt", 0, 0); // 设置某个单元格的值,这个值是一个对象
   friends.doLayout();
   friends.setBackground(Color.lightGray);
   JScrollPane pane1 = new JScrollPane(example1); // JTable最好加在JScrollPane上
   JScrollPane pane2 = new JScrollPane(example2);
   JScrollPane pane3 = new JScrollPane(friends);
   JPanel panel = new JPanel(new GridLayout(0, 1));
   panel.setPreferredSize(new Dimension(600, 400));
   panel.setBackground(Color.black);
   panel.add(pane1);
   panel.add(pane2);
   panel.add(pane3);
   JFrame frame = new JFrame("JTableDemo");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setContentPane(panel);
   frame.pack();
   frame.show();
 }
Exemple #2
0
 private static JTable createUITable(
     boolean keyColumnResizable, int typeWidth, Type type, List<String> lst, Actions editAction) {
   String[] keys = lst.toArray(new String[lst.size()]);
   Arrays.sort(keys);
   TableModel mdl = type == null ? new UITableModel(keys) : new UITypeTableModel(keys, type, true);
   JTable table = new UITable(mdl, null);
   table.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
   table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   table.setRowHeight(25);
   TableColumnModel columns = table.getColumnModel();
   int keyWidth = TABLE_WIDTH - typeWidth - VALUE_WIDTH - DEFAULT_WIDTH;
   columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setMinWidth(keyWidth);
   columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setPreferredWidth(keyWidth);
   columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setResizable(keyColumnResizable);
   Creator.setWidth(columns.getColumn(UITableModel.TYPE_COLUMN_INDEX), typeWidth);
   TableColumn column = columns.getColumn(UITableModel.VALUE_COLUMN_INDEX);
   Creator.setWidth(column, VALUE_WIDTH);
   column.setCellRenderer(new UIDefaultsRenderer());
   column.setCellEditor(new UIDefaultsEditor());
   Creator.setWidth(columns.getColumn(UITableModel.DEFAULT_COLUMN_INDEX), DEFAULT_WIDTH);
   table.setAutoCreateRowSorter(true);
   DefaultRowSorter<?, ?> sorter = (DefaultRowSorter<?, ?>) table.getRowSorter();
   sorter.setSortable(UITableModel.VALUE_COLUMN_INDEX, false);
   table
       .getInputMap(JComponent.WHEN_FOCUSED)
       .put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0), editAction);
   table.getActionMap().put(editAction, editAction);
   return table;
 }
Exemple #3
0
  /**
   * This method initializes tb_result
   *
   * @return javax.swing.JTable
   */
  private JTable getTb_result() {
    if (tb_result == null) {
      TableColumn tc_press = new TableColumn();
      tc_press.setModelIndex(2);
      tc_press.setHeaderValue("출판사");
      TableColumn tc_author = new TableColumn();
      tc_author.setModelIndex(1);
      tc_author.setHeaderValue("저자");
      TableColumn tc_title = new TableColumn();
      tc_title.setHeaderValue("제목");
      tb_result = new JTable();
      tb_result.setAutoCreateColumnsFromModel(false);
      tb_result.setFont(new Font("Dialog", Font.PLAIN, 14));
      tb_result.setRowHeight(30);
      tb_result.addColumn(tc_title);
      tb_result.addColumn(tc_author);
      tb_result.addColumn(tc_press);
      tb_result.addMouseListener(
          new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent e) {
              if (tableMouseClickedCount == 0) {
                tableMouseClickedCount++;
                return;
              }

              Const.goToDetailPage(detailBrowser, getTb_result().getSelectedRow());

              tableMouseClickedCount = 0;
            }
          });
    }
    return tb_result;
  }
  /**
   * Luo tilikarttataulukon.
   *
   * @param container taulukon säiliö
   */
  private void createTable() {
    tableModel = new DocumentTypeTableModel();
    tableModel.setModel(model);

    table = new JTable(tableModel);
    table.setFillsViewportHeight(true);
    table.setPreferredScrollableViewportSize(new Dimension(400, 250));
    table.setRowHeight(24);

    TableColumn column;
    int[] widths = new int[] {80, 140, 80, 80};

    for (int i = 0; i < widths.length; i++) {
      column = table.getColumnModel().getColumn(i);
      column.setPreferredWidth(widths[i]);
    }

    /* Muutetaan enter-näppäimen toiminta. */
    table
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "nextCell");

    table.getActionMap().put("nextCell", nextCellAction);

    add(
        new JScrollPane(
            table,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
        BorderLayout.CENTER);
  }
Exemple #5
0
 /** Calculate the new preferred height for a given row, and sets the height on the table. */
 private void adjustRowHeight(JTable table, int row, int column) {
   // The trick to get this to work properly is to set the width of the column to the
   // textarea. The reason for this is that getPreferredSize(), without a width tries
   // to place all the text in one line. By setting the size with the with of the column,
   // getPreferredSize() returnes the proper height which the row should have in
   // order to make room for the text.
   int cWidth = table.getTableHeader().getColumnModel().getColumn(column).getWidth();
   setSize(new Dimension(cWidth, 1000));
   int prefH = getPreferredSize().height;
   while (rowColHeight.size() <= row) {
     rowColHeight.add(new ArrayList<Integer>(column));
   }
   List<Integer> colHeights = rowColHeight.get(row);
   while (colHeights.size() <= column) {
     colHeights.add(0);
   }
   colHeights.set(column, prefH);
   int maxH = prefH;
   for (Integer colHeight : colHeights) {
     if (colHeight > maxH) {
       maxH = colHeight;
     }
   }
   if (table.getRowHeight(row) != maxH) {
     table.setRowHeight(row, maxH);
   }
 }
  public FileNameRenderer(JTable table) {
    Border b = UIManager.getBorder("Table.noFocusBorder");
    if (Objects.isNull(b)) { // Nimbus???
      Insets i = focusCellHighlightBorder.getBorderInsets(textLabel);
      b = BorderFactory.createEmptyBorder(i.top, i.left, i.bottom, i.right);
    }
    noFocusBorder = b;

    p.setOpaque(false);
    panel.setOpaque(false);

    // http://www.icongalore.com/ XP Style Icons - Windows Application Icon, Software XP Icons
    nicon = new ImageIcon(getClass().getResource("wi0063-16.png"));
    sicon =
        new ImageIcon(
            p.createImage(
                new FilteredImageSource(nicon.getImage().getSource(), new SelectedImageFilter())));

    iconLabel = new JLabel(nicon);
    iconLabel.setBorder(BorderFactory.createEmptyBorder());

    p.add(iconLabel, BorderLayout.WEST);
    p.add(textLabel);
    panel.add(p, BorderLayout.WEST);

    Dimension d = iconLabel.getPreferredSize();
    dim.setSize(d);
    table.setRowHeight(d.height);
  }
  /**
   * Overridden to pass the new rowHeight to the tree.
   *
   * @param rowHeight the new height of the row
   */
  public void setRowHeight(int rowHeight) {
    super.setRowHeight(rowHeight);

    if ((tree != null) && (tree.getRowHeight() != rowHeight)) {
      tree.setRowHeight(getRowHeight());
    }
  }
  public TicketListView() {
    table = new TicketListTable();
    table.setModel(tableModel = new TicketListTableModel());
    table.setRowHeight(40);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    table.setDefaultRenderer(Object.class, new PosTableRenderer());
    table.setGridColor(Color.LIGHT_GRAY);

    TableColumnModel columnModel = table.getColumnModel();
    columnModel.getColumn(0).setPreferredWidth(20);
    columnModel.getColumn(1).setPreferredWidth(20);
    columnModel.getColumn(2).setPreferredWidth(200);
    columnModel.getColumn(3).setPreferredWidth(100);

    JScrollPane scrollPane =
        new JScrollPane(
            table,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
    scrollBar.setPreferredSize(new Dimension(30, 60));

    setLayout(new BorderLayout());

    add(scrollPane);
  }
  private void initTabla() {
    tblHerramientas.setRowHeight(TABLA_DEFAULT_ALTO);
    DefaultTableModel modelo = (DefaultTableModel) tblHerramientas.getModel();

    // Ancho de Columnas
    int anchoColumna = 0;
    TableColumnModel modeloColumna = tblHerramientas.getColumnModel();
    TableColumn columnaTabla;
    for (int i = 0; i < tblHerramientas.getColumnCount(); i++) {
      columnaTabla = modeloColumna.getColumn(i);
      switch (i) {
        case TABLA_HERRAMIENTAS_COLUMNA_ESTADO:
          anchoColumna = 100;
          break;
        case TABLA_HERRAMIENTAS_COLUMNA_NOMBRE:
          anchoColumna = 350;
          break;
        case TABLA_HERRAMIENTAS_COLUMNA_HORAS:
          anchoColumna = 50;
          break;
      }
      columnaTabla.setPreferredWidth(anchoColumna);
      columnaTabla.setWidth(anchoColumna);
    }
  }
  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);
  }
  private void iniciarTabela() {

    tblCliente.setAutoCreateRowSorter(true);
    tblCliente.setRowHeight(35);

    TableColumn colunaDoc = tblCliente.getColumnModel().getColumn(DOCUMENTO);
    TableColumn colunaNome = tblCliente.getColumnModel().getColumn(NOME);
    TableColumn colunaEnd = tblCliente.getColumnModel().getColumn(ENDERECO);
    TableColumn colunaTel = tblCliente.getColumnModel().getColumn(TELEFONE);
    TableColumn colunaEdit = tblCliente.getColumnModel().getColumn(EDITAR);
    TableColumn colunaExcl = tblCliente.getColumnModel().getColumn(EXCLUIR);

    colunaDoc.setPreferredWidth(20);
    colunaNome.setPreferredWidth(200);
    colunaEnd.setPreferredWidth(200);
    colunaTel.setPreferredWidth(20);

    colunaEdit.setMaxWidth(50);
    colunaEdit.setMinWidth(35);
    colunaEdit.setCellRenderer(AbstractTableCrud.getIconCellRenderer());

    colunaExcl.setMaxWidth(50);
    colunaExcl.setMinWidth(35);
    colunaExcl.setCellRenderer(AbstractTableCrud.getIconCellRenderer());
  }
Exemple #12
0
 private void init_tbl_chats() {
   tbl_chats_ALM = new ArrayListModel();
   tbl_chats_M = new TblchatsModel(tbl_chats_ALM);
   tbl_chats.setModel(tbl_chats_M);
   tbl_chats.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
   int[] tbl_widths_chats = {58, 100, 0, 0, 0};
   for (int i = 0, n = tbl_widths_chats.length; i < n; i++) {
     if (i == 1) {
       continue;
     }
     TableWidthUtilities.setColumnWidth(tbl_chats, i, tbl_widths_chats[i]);
   }
   Dimension d = tbl_chats.getTableHeader().getPreferredSize();
   d.height = 0;
   tbl_chats.getTableHeader().setPreferredSize(d);
   tbl_chats.getTableHeader().setFont(new java.awt.Font("Arial", 0, 12));
   tbl_chats.setRowHeight(65);
   tbl_chats.setFont(new java.awt.Font("Arial", 0, 12));
   tbl_chats.getColumnModel().getColumn(0).setCellRenderer(new TableRender.set2());
   tbl_chats.getColumnModel().getColumn(1).setCellRenderer(new TableRender.set3());
   tbl_chats.getTableHeader().setResizingAllowed(true);
   tbl_chats.setShowGrid(false);
   tbl_chats.setShowHorizontalLines(true);
   tbl_chats.setShowVerticalLines(false);
   tbl_chats.getColumnModel().getColumn(1).setCellRenderer(new Html());
 }
 /** Overridden to pass the new rowHeight to the tree. */
 @Override
 public final void setRowHeight(int newRowHeight) {
   super.setRowHeight(newRowHeight);
   if (tree != null && tree.getRowHeight() != newRowHeight) {
     tree.setRowHeight(getRowHeight());
   }
 }
 public CenterPanel(RegisterPanel rp) {
   super();
   setLayout(new BorderLayout());
   this.rp = rp;
   rp.setJT(jt);
   JScrollPane jsp = new JScrollPane(jt);
   setBackground(Color.BLACK);
   add(jsp, BorderLayout.CENTER);
   tm = (DefaultTableModel) jt.getModel();
   tm.addColumn("ID");
   tm.addColumn("Barcode");
   tm.addColumn("Name");
   tm.addColumn("Qty");
   tm.addColumn("Price");
   tm.addColumn("Tax");
   tm.addColumn("Total");
   // tm.setRowCount(50);
   // jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   jt.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
   jt.getColumnModel().getColumn(0).setPreferredWidth(20);
   jt.getColumnModel().getColumn(1).setPreferredWidth(150);
   jt.getColumnModel().getColumn(2).setPreferredWidth(300);
   jt.getColumnModel().getColumn(3).setPreferredWidth(20);
   jt.setFont(new Font("Arial", Font.BOLD, 18));
   jt.setRowHeight(30);
 }
 public CFSecuritySwingISOTimezoneFinderJPanel(ICFSecuritySwingSchema argSchema) {
   super();
   final String S_ProcName = "construct-schema-focus";
   if (argSchema == null) {
     throw CFLib.getDefaultExceptionFactory()
         .newNullArgumentException(getClass(), S_ProcName, 1, "argSchema");
   }
   swingSchema = argSchema;
   dataTable = new JTable(getDataModel(), getDataColumnModel(), getDataListSelectionModel());
   dataTable.addMouseListener(getDataListMouseAdapter());
   dataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   dataTable.setUpdateSelectionOnSort(true);
   dataTable.setRowHeight(25);
   getDataListSelectionModel().addListSelectionListener(getDataListSelectionListener());
   dataScrollPane =
       new JScrollPane(
           dataTable,
           ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
           ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
   dataScrollPane.setColumnHeader(
       new JViewport() {
         @Override
         public Dimension getPreferredSize() {
           Dimension sz = super.getPreferredSize();
           sz.height = 25;
           return (sz);
         }
       });
   dataTable.setFillsViewportHeight(true);
   add(dataScrollPane);
   loadData(true);
   doLayout();
   swingIsInitializing = false;
 }
Exemple #16
0
  ListDetails(int id) {
    setTitle("Filmy należace do listy");
    setSize(500, 200);
    setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    this.setResizable(false);
    setLayout(null);
    frame = this;

    /** ************************************** */
    Object dane[][] = {{"1", "Film 1 "}, {"2", "Film 2"}}; // z bazy danych
    /** ************************************** */
    for (int i = 0; i < dane.length; i++) {
      dane[i] = push(dane[i]);
    }

    Object opisy[] = {"Lp", "Nazwa", ""};
    lista =
        new JTable(dane, opisy) {
          public boolean isCellEditable(int row, int col) // zablokowanie możliwość edycji
              {
            if (col > 1) return true; // do buttonów
            else return false;
          }
        };
    new ButtonColumn(lista, usun, 2);

    lista.setRowHeight(25);
    lista.getColumnModel().getColumn(0).setPreferredWidth(25);
    lista.getColumnModel().getColumn(1).setPreferredWidth(150);

    JScrollPane scrollPane = new JScrollPane(lista);
    scrollPane.setSize(495, 200);
    scrollPane.setLocation(0, 0);
    add(scrollPane);
  }
  private JTable buildTable() {
    JTable table = SwingComponentFactory.buildTable(tableModel, rowSelectionModel);
    int rowHeight = 20; // start with minimum of 20

    table.setRowHeight(rowHeight);

    return table;
  }
Exemple #18
0
  public void mouseDragged(MouseEvent e) {
    int mouseY = e.getY();

    if (resizingRow >= 0) {
      int newHeight = mouseY - mouseYOffset;
      if (newHeight > 0) table.setRowHeight(resizingRow, newHeight);
    }
  }
Exemple #19
0
  protected void addWidgets(DescriptorQueryList list, ActionMap actions, boolean captionsOnly) {
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createTitledBorder(caption));
    setBackground(AmbitColors.BrightClr);
    setForeground(AmbitColors.DarkClr);

    tableModel = new DescriptorQueryTableModel(list, captionsOnly);
    JTable table = new JTable(tableModel, createTableColumnModel(tableModel, captionsOnly));
    table.setSurrendersFocusOnKeystroke(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setRowSelectionAllowed(false);
    table.getTableHeader().setReorderingAllowed(false);
    table.setRowHeight(24);

    TableColumn col;

    int[] pSize = {32, 240, 32, 32, 64, 32, 32, 32};
    int[] mSize = {24, 120, 32, 32, 64, 32, 32, 32};
    for (int i = 0; i < table.getColumnCount(); i++) {
      col = table.getColumnModel().getColumn(i);
      col.setPreferredWidth(pSize[i]);
      col.setMinWidth(mSize[i]);
    }
    // table.setShowGrid(false);
    table.setShowHorizontalLines(true);
    table.setShowVerticalLines(false);

    scrollPane = new JScrollPane(table);
    scrollPane.setPreferredSize(new Dimension(420, 360));
    scrollPane.setMinimumSize(new Dimension(370, 120));
    scrollPane.setAutoscrolls(true);

    // tPane.addTab("Search descriptors",scrollPane);
    add(scrollPane, BorderLayout.CENTER);
    /*
    JToolBar t = new JToolBar();
    //t.setBackground(Color.white);
    t.setFloatable(false);
    //t.setBorder(BorderFactory.createTitledBorder("Search by descriptors and distance between atoms"));
    Object[] keys = actions.allKeys();
    if (keys != null) {
     for (int i=0; i < keys.length;i++)
     	t.add(actions.get(keys[i]));
     add(t,BorderLayout.SOUTH);
    }
    */
    if (actions != null) {
      Object[] keys = actions.allKeys();
      if (keys != null) {
        for (int i = 0; i < keys.length; i++) {
          add(
              new DescriptorSearchActionPanel(list, actions.get(keys[i]), keys[i].toString()),
              BorderLayout.SOUTH);
          break;
        }
      }
    }
  }
  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);
  }
 private void Table(javax.swing.JTable tb, int lebar[]) {
   tb.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   int kolom = tb.getColumnCount();
   for (int i = 0; i < kolom; i++) {
     javax.swing.table.TableColumn tbc = tb.getColumnModel().getColumn(i);
     tbc.setPreferredWidth(lebar[i]);
     tb.setRowHeight(17);
   }
 }
  @Override
  public int getRowHeight(int row) {
    int rowHeight = main.getRowHeight(row);

    if (rowHeight != super.getRowHeight(row)) {
      super.setRowHeight(row, rowHeight);
    }

    return rowHeight;
  }
 public Component getTableCellRendererComponent(
     JTable jTable, Object obj, boolean isSelected, boolean hasFocus, int row, int column) {
   // set color & border here
   setText(obj == null ? "" : obj.toString());
   setSize(jTable.getColumnModel().getColumn(column).getWidth(), getPreferredSize().height);
   if (jTable.getRowHeight(row) != getPreferredSize().height) {
     jTable.setRowHeight(row, getPreferredSize().height);
   }
   return this;
 }
Exemple #24
0
  private void setupTab() {

    // The chat area
    BorderLayout chatLayout = new BorderLayout();
    JPanel chatWrapper = new JPanel(chatLayout);

    chatLog = new JTextPane();
    chatLog.setEditable(false);
    chatLog.setDocument(new ChatDocument());
    chatLogScrollPane = new JScrollPane(chatLog);
    chatLogScrollPane.addMouseListener(this);

    chatWrapper.add(chatLogScrollPane, BorderLayout.CENTER);

    // The send message panel
    message = new JTextArea();
    message.addMouseListener(this);
    message.addKeyListener(this);
    messageScrollPane = new JScrollPane(message);
    message.setLineWrap(true);
    message.setWrapStyleWord(true);
    message.requestFocus();
    message.setDocument(new JTextFieldLimit(512));

    sendMessage = new JButton("Send", frame.getGui().getUtil().getImage("sendmessage"));
    sendMessage.addMouseListener(this);
    sendMessage.addActionListener(this);

    chatMessagePanel = new JPanel();
    chatMessagePanel.setLayout(new BoxLayout(chatMessagePanel, BoxLayout.X_AXIS));
    chatMessagePanel.add(messageScrollPane);
    chatMessagePanel.add(sendMessage);

    chatWrapper.add(chatMessagePanel, BorderLayout.PAGE_END);

    // Setup the avatars
    avatarTable = new JTable(new AvatarTableModel(indexNode));
    avatarTable.addMouseListener(this);
    avatarTable.setTableHeader(null);
    avatarTable.setDefaultRenderer(Object.class, new AvatarRenderer(frame));
    avatarTable.setRowHeight(70);
    avatarScrollPane = new JScrollPane(avatarTable);
    avatarScrollPane.setMaximumSize(new Dimension(200, -1));
    avatarScrollPane.setPreferredSize(new Dimension(200, -1));

    // Add all to parent
    BorderLayout pageLayout = new BorderLayout();

    this.setLayout(pageLayout);
    this.add(avatarScrollPane, BorderLayout.LINE_END);
    this.add(chatWrapper, BorderLayout.CENTER);

    // Set the status
    active = true;
  }
  /* Magic Happens */
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    /* If what we're displaying isn't an array of values we
    return the normal renderer*/

    if (value == null || (!value.getClass().isArray())) {
      return table
          .getDefaultRenderer(value.getClass())
          .getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    } else {
      final Object[][] passed = (Object[][]) value;
      /* We calculate the row's height to display data
       * THis is not complete and has some bugs that
       * will be analyzed in further articles */
      if (tbl_row_height == -1) {
        tbl_row_height = table.getRowHeight();
      }
      if (curr_height != tbl_row_height) {
        curr_height = (passed.length * passed.length + 20) + tbl_row_height;

        table.setRowHeight(row, curr_height);
      }

      /* We create the table that will hold the multi value
       *fields and that will be embedded in the main table */

      JTable tbl =
          new JTable(
              new AbstractTableModel() {

                private static final long serialVersionUID = 1L;

                public int getColumnCount() {
                  return 2;
                }

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

                public Object getValueAt(int rowIndex, int columnIndex) {

                  return passed[rowIndex][columnIndex];
                }

                public boolean isCellEditable(int row, int col) {
                  return true;
                }
              });

      tbl.setShowGrid(false);

      return tbl;
    }
  }
 public CFInternetSwingVersionListJPanel(
     ICFInternetSwingSchema argSchema,
     ICFLibAnyObj argContainer,
     ICFInternetVersionObj argFocus,
     Collection<ICFInternetVersionObj> argDataCollection,
     ICFJRefreshCallback refreshCallback,
     boolean sortByChain) {
   super();
   final String S_ProcName = "construct-schema-focus";
   if (argSchema == null) {
     throw CFLib.getDefaultExceptionFactory()
         .newNullArgumentException(getClass(), S_ProcName, 1, "argSchema");
   }
   // argFocus is optional; focus may be set later during execution as
   // conditions of the runtime change.
   swingSchema = argSchema;
   swingFocus = argFocus;
   swingContainer = argContainer;
   swingRefreshCallback = refreshCallback;
   swingSortByChain = sortByChain;
   setSwingDataCollection(argDataCollection);
   dataTable = new JTable(getDataModel(), getDataColumnModel(), getDataListSelectionModel());
   dataTable.addMouseListener(getDataListMouseAdapter());
   dataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   dataTable.setUpdateSelectionOnSort(true);
   dataTable.setRowHeight(25);
   getDataListSelectionModel().addListSelectionListener(getDataListSelectionListener());
   dataScrollPane =
       new JScrollPane(
           dataTable,
           ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
           ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
   dataScrollPane.setColumnHeader(
       new JViewport() {
         @Override
         public Dimension getPreferredSize() {
           Dimension sz = super.getPreferredSize();
           sz.height = 25;
           return (sz);
         }
       });
   dataTable.setFillsViewportHeight(true);
   // Do initial layout
   setSize(1024, 480);
   JMenuBar menuBar = getPanelMenuBar();
   add(menuBar);
   menuBar.setBounds(0, 0, 1024, 25);
   add(dataScrollPane);
   dataScrollPane.setBounds(0, 25, 1024, 455);
   adjustListMenuBar();
   doLayout();
   swingIsInitializing = false;
 }
 private void init_tbl_delivery_trucks() {
   tbl_delivery_trucks_ALM = new ArrayListModel();
   tbl_delivery_trucks_M = new Tbldelivery_trucksModel(tbl_delivery_trucks_ALM);
   tbl_delivery_trucks.getTableHeader().setPreferredSize(new Dimension(100, 40));
   tbl_delivery_trucks.setModel(tbl_delivery_trucks_M);
   tbl_delivery_trucks.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
   tbl_delivery_trucks.setRowHeight(25);
   int[] tbl_widths_delivery_trucks = {100, 100, 0};
   for (int i = 0, n = tbl_widths_delivery_trucks.length; i < n; i++) {
     if (i == 1) {
       continue;
     }
     TableWidthUtilities.setColumnWidth(tbl_delivery_trucks, i, tbl_widths_delivery_trucks[i]);
   }
   Dimension d = tbl_delivery_trucks.getTableHeader().getPreferredSize();
   d.height = 25;
   tbl_delivery_trucks.getTableHeader().setPreferredSize(d);
   tbl_delivery_trucks.getTableHeader().setFont(new java.awt.Font("Arial", 0, 11));
   tbl_delivery_trucks.setRowHeight(35);
   tbl_delivery_trucks.setFont(new java.awt.Font("Arial", 0, 11));
 }
  /** 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);
  }
 private void buildWin() {
   jpbLoading = new JProgressBar(0, 100);
   jfcBrowse = new JFileChooser(Initial.DB_CONFIG_PATH);
   jlConfigPath = new JLabel("配置文件路径:");
   jlStatus = new JLabel("未操作");
   jlConfigPath.setFont(SwingContainerFactory.getFont());
   jlStatus.setFont(SwingContainerFactory.getFont());
   jlStatus.setForeground(Color.RED);
   jpOperatingDbInfo = new JPanel();
   jpStatusBar = new JPanel(new BorderLayout());
   jpDisplay = new JPanel(new BorderLayout());
   jbAddDbInfo = new JButton("添加");
   jbDelDbInfo = new JButton("删除");
   jbSaveDbInfo = new JButton("保存");
   jbBrowse = new JButton("浏览...");
   jbLoadDbInfo = new JButton("加载");
   jbClearDbInfo = new JButton("清空");
   jtfConfigPath = new JTextField(20);
   jbAddDbInfo.setFont(SwingContainerFactory.getFont());
   jbDelDbInfo.setFont(SwingContainerFactory.getFont());
   jbSaveDbInfo.setFont(SwingContainerFactory.getFont());
   jbBrowse.setFont(SwingContainerFactory.getFont());
   jbLoadDbInfo.setFont(SwingContainerFactory.getFont());
   jbClearDbInfo.setFont(SwingContainerFactory.getFont());
   jpOperatingDbInfo.add(jbAddDbInfo);
   jpOperatingDbInfo.add(jbDelDbInfo);
   jpOperatingDbInfo.add(jbClearDbInfo);
   jpOperatingDbInfo.add(jbSaveDbInfo);
   jpOperatingDbInfo.add(jlConfigPath);
   jpOperatingDbInfo.add(jtfConfigPath);
   jpOperatingDbInfo.add(jbBrowse);
   jpOperatingDbInfo.add(jbLoadDbInfo);
   jpStatusBar.add(jpbLoading, BorderLayout.CENTER);
   jpStatusBar.add(jlStatus, BorderLayout.WEST);
   tmDbInfo = new Table();
   jtDbinfo = new JTable(tmDbInfo);
   jtDbinfo.setRowHeight(20);
   jtDbinfo.setBackground(Color.white);
   jtDbinfo.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   TableColumnModel tcm = jtDbinfo.getColumnModel();
   for (int i = 0; i < tcm.getColumnCount(); i++) {
     tcm.getColumn(i).setPreferredWidth(80);
   }
   tcm.getColumn(10).setPreferredWidth(150);
   tcm.getColumn(11).setPreferredWidth(300);
   tcm.getColumn(3).setCellEditor(new DefaultCellEditor(new JComboBox<DBType>(DBType.values())));
   jspDbInfo = new JScrollPane(jtDbinfo);
   jpDisplay.add(jspDbInfo, BorderLayout.CENTER);
   jpDisplay.add(jpOperatingDbInfo, BorderLayout.NORTH);
   this.add(jpDisplay, BorderLayout.CENTER);
   this.add(jpStatusBar, BorderLayout.SOUTH);
 }
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    if (value != null) setText(value.toString());

    setSize(table.getColumnModel().getColumn(column).getWidth(), getPreferredSize().height);

    if (table.getRowHeight(row) != getPreferredSize().height) {
      table.setRowHeight(row, getPreferredSize().height);
    }

    return this;
  }