コード例 #1
0
ファイル: Table.java プロジェクト: sfrancis1970/EpochX
  /** Adjust the preferred size of the <code>Table</code>. */
  private void adjustPreferredSize() {
    // Refresh the model
    model.refresh();

    int preferredWidth = 20;
    TableColumn col = null;

    for (Enumeration<TableColumn> e = table.getColumnModel().getColumns(); e.hasMoreElements(); ) {
      col = e.nextElement();

      // Calculs & sets the preferred width of the cells.
      int colPreferredWidth = col.getPreferredWidth();
      for (int i = 0; i < table.getRowCount(); i++) {
        int cellWidth =
            table
                    .getTableHeader()
                    .getFontMetrics(table.getTableHeader().getFont())
                    .stringWidth(model.getValueAt(i, col.getModelIndex()).toString())
                + 5;
        if (cellWidth > colPreferredWidth) colPreferredWidth = cellWidth;
      }

      // Increments the table preferred width.
      col.setPreferredWidth(colPreferredWidth);

      // Increments the table preferred width.
      preferredWidth += colPreferredWidth;
    }
    // Set the preferred size.
    setPreferredSize(new Dimension(preferredWidth, (int) getPreferredSize().getHeight()));
  }
コード例 #2
0
 /**
  * auto fit table columns width
  *
  * @version 1.0
  * @author dinglinhui
  */
 public void FitTableColumns(JTable myTable) {
   JTableHeader header = myTable.getTableHeader();
   int rowCount = myTable.getRowCount();
   Enumeration columns = myTable.getColumnModel().getColumns();
   while (columns.hasMoreElements()) {
     TableColumn column = (TableColumn) columns.nextElement();
     int col = header.getColumnModel().getColumnIndex(column.getIdentifier());
     int width =
         (int)
             myTable
                 .getTableHeader()
                 .getDefaultRenderer()
                 .getTableCellRendererComponent(
                     myTable, column.getIdentifier(), false, false, -1, col)
                 .getPreferredSize()
                 .getWidth();
     for (int row = 0; row < rowCount; row++) {
       int preferedWidth =
           (int)
               myTable
                   .getCellRenderer(row, col)
                   .getTableCellRendererComponent(
                       myTable, myTable.getValueAt(row, col), false, false, row, col)
                   .getPreferredSize()
                   .getWidth();
       width = Math.max(width, preferedWidth);
     }
     header.setResizingColumn(column); // 此行很重要
     column.setWidth(width + myTable.getIntercellSpacing().width);
   }
 }
コード例 #3
0
  /**
   * This method initializes jTableTitular
   *
   * @return javax.swing.JTable
   */
  private JTable getJTableTitular() {
    if (jTableTitular == null) {
      jTableTitular = new JTable();

      tablepersonamodel = new TablePersonaModel();

      TableSorted tblSorted = new TableSorted(tablepersonamodel);
      tblSorted.setTableHeader(jTableTitular.getTableHeader());
      jTableTitular.setModel(tblSorted);
      jTableTitular.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      jTableTitular.setCellSelectionEnabled(false);
      jTableTitular.setColumnSelectionAllowed(false);
      jTableTitular.setRowSelectionAllowed(true);
      jTableTitular.getTableHeader().setReorderingAllowed(false);

      ArrayList lst = new ArrayList();
      lst.add(new Persona());
      ((TablePersonaModel) ((TableSorted) jTableTitular.getModel()).getTableModel()).setData(lst);

      /*
      EdicionOperations oper = new EdicionOperations();
      try
      {
          ArrayList lstVias = oper.obtenerViasCatastro();
          ((TableViasCatastroModel)((TableSorted)jTableViasCatastro.getModel()).getTableModel()).setData(lstVias);

      } catch (DataException e1)
      {
          e1.printStackTrace();
      }
      */
    }
    return jTableTitular;
  }
コード例 #4
0
ファイル: MultiDiffPanel.java プロジェクト: celsocosta/nbgit
  private void updateSplitLocation() {
    if (dividerSet) {
      return;
    }
    JComponent parent = (JComponent) getParent();
    Dimension dim = parent == null ? new Dimension() : parent.getSize();
    if (dim.width <= 0 || dim.height <= 0) {
      SwingUtilities.invokeLater(
          new Runnable() {

            public void run() {
              updateSplitLocation();
            }
          });
    }
    dividerSet = true;
    JTable jt = fileTable.getTable();
    int optimalLocation =
        jt.getPreferredSize().height + jt.getTableHeader().getPreferredSize().height;
    if (optimalLocation > dim.height / 3) {
      optimalLocation = dim.height / 3;
    }
    if (optimalLocation <= jt.getTableHeader().getPreferredSize().height) {
      optimalLocation = jt.getTableHeader().getPreferredSize().height * 3;
    }
    splitPane.setDividerLocation(optimalLocation);
  }
コード例 #5
0
ファイル: Dlg_chat.java プロジェクト: yespickmeup/Synsoftech
 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());
 }
コード例 #6
0
  /**
   * Fügt einem Container eine JTable mit den Daten, der Beschriftung und dem Titel hinzu.
   *
   * @param tabs JTabbedPane
   * @param daten Daten
   * @param kopfZeile Beschriftung
   * @param s Titel
   */
  protected static void fuegeJTabelleHinzu(
      Container tabs, Object[][] daten, Object[] kopfZeile, String s) {

    TableModel model =
        new DefaultTableModel(daten, kopfZeile) {
          private static final long serialVersionUID = 1L;

          @SuppressWarnings({"rawtypes", "unchecked"})
          @Override
          public Class getColumnClass(int column) {
            return getValueAt(0, column).getClass();
          }
        };

    JTable jTabelle = new JTable(model);
    jTabelle.getTableHeader().setFont(DiagrammeErsteller.STANDARD2);
    jTabelle.setFont(DiagrammeErsteller.STANDARD3);
    jTabelle.setEnabled(false);
    jTabelle.getTableHeader().setReorderingAllowed(false);
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    jTabelle.setRowSorter(sorter);
    if (tabs.getClass() == JTabbedPane.class) {
      JTabbedPane t = (JTabbedPane) tabs;
      t.addTab(
          s,
          new JScrollPane(
              jTabelle,
              JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
              JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
    } else {
      tabs.add(new JScrollPane(jTabelle));
    }
  }
コード例 #7
0
ファイル: BetterJTable.java プロジェクト: tommyjasmin/mcidasv
  /** Paints the given JTable's table default header background at given x for the given width. */
  private static void paintHeader(Graphics g, JTable table, int x, int width) {
    TableCellRenderer renderer = table.getTableHeader().getDefaultRenderer();
    Component component = renderer.getTableCellRendererComponent(table, "", false, false, -1, 2);

    component.setBounds(0, 0, width, table.getTableHeader().getHeight());

    ((JComponent) component).setOpaque(false);
    CELL_RENDER_PANE.paintComponent(
        g, component, null, x, 0, width, table.getTableHeader().getHeight(), true);
  }
コード例 #8
0
  /**
   * Method for creating and setting up the table for showing to do items to the user.
   *
   * @return Returns the table.
   */
  private JTable createTable() {
    JTable table = new JTable(tableModel);
    table.setAutoCreateRowSorter(true);
    table.getTableHeader().setReorderingAllowed(false);
    table
        .getModel()
        .addTableModelListener(
            this); // should catch changes in the table model once we promote them with the
                   // fireUpdate() below.

    table.getTableHeader().setFont(new Font("Arial", Font.PLAIN, 13));

    return table;
  }
コード例 #9
0
  private void packColumn(JTable table, int vColIndex, int margin) {
    //		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width = 0;

    // obtiene la anchura de la cabecera de la columna
    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;
    width = 5;

    // Obtine la anchura maxima de la coluna de
    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, 0);
    }

    width += 2 * margin;

    // Configura el ancho
    col.setPreferredWidth(width);
  }
コード例 #10
0
ファイル: SessionMgrPanel.java プロジェクト: jdepend/cooper
  private JTable initSessionList() {

    final JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem removeItem = new JMenuItem(BundleUtil.getString(BundleUtil.Command_Delete));
    removeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            remove();
          }
        });
    popupMenu.add(removeItem);

    sessionListModel =
        new DefaultTableModel() {
          @Override
          public boolean isCellEditable(int row, int column) {
            return false;
          }
        };

    TableSorter sorter = new TableSorter(sessionListModel);

    JTable sessionsTable = new JTable(sorter);

    sessionsTable.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            JTable table = (JTable) e.getSource();
            int currentRow = table.rowAtPoint(e.getPoint());
            if (currentRow >= 0) {
              table.setRowSelectionInterval(currentRow, currentRow);
            }
          }

          @Override
          public void mousePressed(MouseEvent e) {
            JTable table = (JTable) e.getSource();
            int currentRow = table.rowAtPoint(e.getPoint());
            if (currentRow >= 0) {
              table.setRowSelectionInterval(currentRow, currentRow);
            }
            currentSession = (Long) table.getValueAt(table.rowAtPoint(e.getPoint()), 0);
            if (e.getButton() == 3) {
              popupMenu.show(table, e.getX(), e.getY());
            }
          }
        });

    sorter.setTableHeader(sessionsTable.getTableHeader());

    sessionListModel.addColumn("会话ID");
    sessionListModel.addColumn("用户名");
    sessionListModel.addColumn("IP地址");
    sessionListModel.addColumn("创建时间");
    sessionListModel.addColumn("操作");
    sessionListModel.addColumn("注销时间");

    return sessionsTable;
  }
コード例 #11
0
  public JDinkShowSequencesInfoPanel(JDinkContext context) {
    super(new BorderLayout());
    this.context = context;
    this.setMinimumSize(new Dimension(100, 100));
    this.setSize(new Dimension(100, 100));

    JPanel bottomPanel = new JPanel(new BorderLayout());
    bottomPanel.add(label = new JLabel("last updated: "), BorderLayout.SOUTH);
    this.add(bottomPanel, BorderLayout.SOUTH);

    final JButton refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            update();
          }
        });
    this.add(refreshButton, BorderLayout.NORTH);
    JPanel panel = new JPanel(new BorderLayout());
    JTable table = new JTable(model = new SequenceTableModel());
    panel.add(table.getTableHeader(), BorderLayout.PAGE_START);
    panel.add(new JScrollPane(table), BorderLayout.CENTER);
    this.add(panel, BorderLayout.CENTER);
    //		model.setRows(Arrays.asList(new CollisionInformation(new JDinkHardnessCollisionImpl((byte)
    // 10))));
    //		enable();
    //		update();
  }
コード例 #12
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));
 }
コード例 #13
0
ファイル: JTableHelper.java プロジェクト: Kaito-KY/weka-1
  /**
   * Calculates the optimal width for the header of the given table. The calculation is based on the
   * preferred width of the header renderer.
   *
   * @param table the table to calculate the column width
   * @param col the column to calculate the widths
   * @return the width, -1 if error
   */
  public static int calcHeaderWidth(JTable table, int col) {
    if (table == null) return -1;

    if (col < 0 || col > table.getColumnCount()) {
      System.out.println("invalid col " + col);
      return -1;
    }

    JTableHeader header = table.getTableHeader();
    TableCellRenderer defaultHeaderRenderer = null;
    if (header != null) defaultHeaderRenderer = header.getDefaultRenderer();
    TableColumnModel columns = table.getColumnModel();
    TableModel data = table.getModel();
    TableColumn column = columns.getColumn(col);
    int width = -1;
    TableCellRenderer h = column.getHeaderRenderer();
    if (h == null) h = defaultHeaderRenderer;
    if (h != null) {
      // Not explicitly impossible
      Component c =
          h.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, col);
      width = c.getPreferredSize().width + 5;
    }

    return width;
  }
コード例 #14
0
  private static int preferredWidth(JTable table, int col) {
    TableColumn tableColumn = table.getColumnModel().getColumn(col);
    int width =
        (int)
            table
                .getTableHeader()
                .getDefaultRenderer()
                .getTableCellRendererComponent(
                    table, tableColumn.getIdentifier(), false, false, -1, col)
                .getPreferredSize()
                .getWidth();

    if (table.getRowCount() != 0) {
      int from = 0, to = 0;
      Rectangle rect = table.getVisibleRect();
      from = table.rowAtPoint(rect.getLocation());
      to = table.rowAtPoint(new Point((int) rect.getMaxX(), (int) rect.getMaxY())) + 1;

      for (int row = from; row < to; row++) {
        int preferedWidth =
            (int)
                table
                    .getCellRenderer(row, col)
                    .getTableCellRendererComponent(
                        table, table.getValueAt(row, col), false, false, row, col)
                    .getPreferredSize()
                    .getWidth();
        width = Math.max(width, preferedWidth);
      }
    }
    return width + table.getIntercellSpacing().width;
  }
コード例 #15
0
ファイル: StudentG.java プロジェクト: robin1501/Projektarbeit
  private void createandAddTable(String[][] rowData2, String[] columnNames2) {

    jtNotenAnzeige =
        new JTable(rowData2, columnNames2) {

          private static final long serialVersionUID = 1L;

          public boolean isCellEditable(int row, int column) {
            // set table column uneditable
            return false;
          }
        };
    jtNotenAnzeige.setRowSelectionAllowed(false);
    jtNotenAnzeige.getTableHeader().setReorderingAllowed(false);

    // / scrollPane removen weil dann tabelle !
    if (scrollPane != null) {
      tablePanel.remove(scrollPane);
    }

    scrollPane = new JScrollPane(jtNotenAnzeige);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBounds(10, 21, 525, 261);
    tablePanel.add(scrollPane);
  }
コード例 #16
0
  /** TableCellRenderer implementation */
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // Try to set default fore- and background colors
    if (table != null) {
      JTableHeader header = table.getTableHeader();
      if (header != null) {
        setForeground(header.getForeground());
        setBackground(header.getBackground());
        setFont(header.getFont());
        AbstractTableModel model = (AbstractTableModel) table.getModel();

        column = table.convertColumnIndexToModel(column);
        setText(model.getColumnName(column));
        // set normal border
        setBorder(javax.swing.UIManager.getBorder("TableHeader.cellBorder"));

        if (m_sortmode == SortMode.ASCENDING) setIcon(m_upimage);
        else if (m_sortmode == SortMode.DESCENDING) setIcon(m_downimage);
        else
          // if NONE
          setIcon(m_emptyheaderimage);
      }
    }
    return this;
  }
コード例 #17
0
  private void refreshMotionTable() {
    final int COL_MOTION = 0;
    final int COL_START_FRAME = 1;
    final int COL_END_FRAME = 2;
    motionTable.setModel(
        new DefaultTableModel() {
          private static final long serialVersionUID = 1L;

          @Override
          public int getRowCount() {
            return project.getMotions().size();
          }

          @Override
          public int getColumnCount() {
            return 3;
          }

          @Override
          public String getColumnName(int columnIndex) {
            switch (columnIndex) {
              case COL_MOTION:
                return "Motion";
              case COL_START_FRAME:
                return "Start";
              case COL_END_FRAME:
                return "End";
            }
            return null;
          }

          @Override
          public Object getValueAt(int rowIndex, int columnIndex) {
            Motion motion =
                rowIndex < project.getMotions().size() ? project.getMotions().get(rowIndex) : null;
            if (motion != null) {
              switch (columnIndex) {
                case COL_MOTION:
                  return motion.getDisplayLabel();
                case COL_START_FRAME:
                  return (motion.getStartFrame() != null)
                      ? String.valueOf(motion.getStartFrame())
                      : "";
                case COL_END_FRAME:
                  return (motion.getEndFrame() != null) ? String.valueOf(motion.getEndFrame()) : "";
              }
            }
            return null;
          }

          @Override
          public boolean isCellEditable(int row, int column) {
            return false;
          }
        });
    motionTable.getTableHeader().setFont(motionTable.getFont());
    motionTable.getColumnModel().getColumn(COL_MOTION).setWidth(120);
    motionTable.getColumnModel().getColumn(COL_START_FRAME).setPreferredWidth(10);
    motionTable.getColumnModel().getColumn(COL_END_FRAME).setWidth(10);
  }
コード例 #18
0
ファイル: TextAreaRenderer.java プロジェクト: rdo/Unifinder
 /** 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);
   }
 }
コード例 #19
0
ファイル: Main.java プロジェクト: richevan3891/SE-300
  public static Component CreateRouteTable(Object[][] data, Dimension totalSize) {
    String[] columnNames = {
      "Route #",
      "Carrier",
      "Dep. Airport",
      "Dep. Time",
      "Arr. Airport",
      "Arr. Time",
      "Price",
      "status"
    };

    // disable cell editing
    JTable routeTable =
        new JTable(data, columnNames) {
          public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
          };
        };
    routeTable.getTableHeader().setReorderingAllowed(false);
    routeTable.getTableHeader().setResizingAllowed(false);
    JScrollPane routeTableScroll =
        new JScrollPane(routeTable); // create the routes table in a scrollPane

    routeTableScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    routePanelWidth = (totalSize.width * 3 / 4) * 48 / 100;
    routePanelHeight = totalSize.height * 45 / 100;
    routeTableScroll.setPreferredSize(new Dimension(routePanelWidth, routePanelHeight));
    return routeTableScroll;
  }
コード例 #20
0
 public void cargarTabla(ArrayList<Alumno> alumnos) {
   XTableModelAlumnos modelo = new XTableModelAlumnos();
   modelo.setDatasource(alumnos);
   table.getTableHeader().setReorderingAllowed(false);
   table.setModel(modelo);
   btnAgregarAlumnos.setEnabled(true);
 }
コード例 #21
0
  /**
   * Create the {@link #projectsTableModel}, {@link #projectsTable} and {@link
   * #projectsTableRowSorter}
   */
  private void createProjectsTable() {
    projectsTableModel =
        Utils.createUneditableTableModel(
            "Project",
            "Skipped?",
            "<html>Comp<br>Warn</html>",
            "<html>Comp<br>Err</html>",
            "<html>Link<br>Warn</html>",
            "<html>Link<br>Err</html>",
            "Includes?");
    projectsTable = new JTable(projectsTableModel);
    projectsTable.getTableHeader().setReorderingAllowed(false);

    projectsTableRowSorter = new TableRowSorter<DefaultTableModel>(projectsTableModel);
    projectsTable.setRowSorter(projectsTableRowSorter);

    projectsTable.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              int viewRow = projectsTable.rowAtPoint(e.getPoint());
              int modelRow = projectsTable.convertRowIndexToModel(viewRow);
              openBuildOutputFrame(buildOutputs.get(modelRow));
            }
          }
        });

    projectsTable.setToolTipText("Double-click to open");
  }
コード例 #22
0
  public void ListePaletteConteneur(int numero) {

    try {

      Connexion connec = new Connexion(Connexion.log, Connexion.password);
      ResultSet rs = connec.listerPaletteConteneur(numero);

      if (rs.next()) {

        rs.previous();

        String[] nomColonnes = {"id_colis"};

        LinkedList<Object[]> liste = new LinkedList<Object[]>();
        Object[][] donnees;

        while (rs.next()) {
          Object[] data = new Object[8];

          data[0] = rs.getString(1);

          liste.add(data);
        }

        donnees = new Object[liste.size()][];

        for (int i = 0; i < donnees.length; i++) {
          donnees[i] = liste.get(i);
        }

        for (int i = 0; i < 8; i++) System.out.println(nomColonnes[i]);
        table = new JTable(donnees, nomColonnes);

        jp = new JPanel();

        jp.setLayout(new BorderLayout());
        jp.add(table.getTableHeader(), BorderLayout.PAGE_START);
        scroll = new JScrollPane(table);

        jp.add(scroll, BorderLayout.CENTER);

        jp.setVisible(true);
        jp.setSize(800, 700);

        fermer.addActionListener(this);
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(jp, BorderLayout.CENTER);
        panel.add(fermer, BorderLayout.SOUTH);
        this.setContentPane(panel);
        this.setVisible(true);
      }

    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
コード例 #23
0
ファイル: StudentG.java プロジェクト: robin1501/Projektarbeit
  private void createAndMarkAndAddTable(String[][] rowData2, String[] columnNames2) {

    jtNotenAnzeige =
        new JTable(rowData2, columnNames2) {

          private static final long serialVersionUID = 1L;

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

    jtNotenAnzeige.setRowSelectionAllowed(false);
    jtNotenAnzeige.getTableHeader().setReorderingAllowed(false);
    jtNotenAnzeige.setDefaultRenderer(Object.class, new ColorTableCellRenderer());

    if (scrollPane != null) {
      tablePanel.remove(scrollPane);
    }

    scrollPane = new JScrollPane(jtNotenAnzeige);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBounds(10, 21, 525, 261);
    tablePanel.add(scrollPane);
  }
コード例 #24
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();
              }
            });
  }
コード例 #25
0
  public static void pack(JTable table) {

    if (!table.isShowing() || table.getColumnCount() == 0) return;

    int width[] = new int[table.getColumnCount()];
    int total = 0;
    for (int col = 0; col < width.length; col++) {
      width[col] = preferredWidth(table, col);
      total += width[col];
    }

    int extra = table.getVisibleRect().width - total;
    if (extra > 0) {

      int bonus = extra / table.getColumnCount();
      for (int i = 0; i < width.length; i++) {
        width[i] += bonus;
      }
      extra -= bonus * table.getColumnCount();

      width[width.length - 1] += extra;
    }

    TableColumnModel columnModel = table.getColumnModel();
    for (int col = 0; col < width.length; col++) {
      TableColumn tableColumn = columnModel.getColumn(col);
      table.getTableHeader().setResizingColumn(tableColumn);
      tableColumn.setWidth(width[col]);
    }
  }
  /** Erzeugt die Tabelle für die Anzeige der Medien. */
  private void erzeugeMedienTable() {
    JScrollPane medienAuflisterScrollPane = new JScrollPane();
    medienAuflisterScrollPane.setBorder(
        BorderFactory.createTitledBorder(
            null,
            "Medien",
            TitledBorder.LEADING,
            TitledBorder.DEFAULT_POSITION,
            UIConstants.HEADER_FONT));
    medienAuflisterScrollPane.setBackground(UIConstants.BACKGROUND_COLOR);
    medienAuflisterScrollPane.getVerticalScrollBar().setBackground(UIConstants.BACKGROUND_COLOR);
    medienAuflisterScrollPane.getHorizontalScrollBar().setBackground(UIConstants.BACKGROUND_COLOR);

    _ausleiheMedienTableModel = new MedienverwaltungMedienTableModel();
    _medienTable = new JTable();
    _medienTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    medienAuflisterScrollPane.setViewportView(_medienTable);
    _medienTable.setModel(_ausleiheMedienTableModel);
    JTableHeader tableHeader = _medienTable.getTableHeader();
    tableHeader.setFont(UIConstants.HEADER_FONT);
    tableHeader.setReorderingAllowed(false);
    tableHeader.setResizingAllowed(false);
    _medienTable.setFont(UIConstants.TEXT_FONT);

    _hauptPanel.add(medienAuflisterScrollPane, BorderLayout.CENTER);
  }
コード例 #27
0
ファイル: DataTablePanel.java プロジェクト: rstjohn/latiz
  public void 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);
  }
コード例 #28
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);
  }
コード例 #29
0
  private void createUIComponents() {
    mainPanel = new DollarPanel();

    graphicOfPayments = new JTable();
    JTableHeader header = graphicOfPayments.getTableHeader();
    header.setPreferredSize(new Dimension(graphicOfPayments.getWidth(), HEADERS_HEIGHT));
  }
コード例 #30
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();
  }