private static Rectangle fitToScreen(
     @NotNull Dimension newDim, @NotNull RelativePoint popupPosition, JTable table) {
   Rectangle rectangle = new Rectangle(popupPosition.getScreenPoint(), newDim);
   ScreenUtil.fitToScreen(rectangle);
   if (rectangle.getHeight() != newDim.getHeight()) {
     int newHeight = (int) rectangle.getHeight();
     int roundedHeight = newHeight - newHeight % table.getRowHeight();
     rectangle.setSize((int) rectangle.getWidth(), Math.max(roundedHeight, table.getRowHeight()));
   }
   return rectangle;
 }
Example #2
0
    public void showPopup() {
      if (getTxtSearch().isShowing()) {
        int wd = getTxtSearch().getWidth();
        if (widthD != 0) {
          wd = widthD;
        }
        if (table.getRowCount() > 7) {
          setPopupSize(wd, table.getRowHeight() * 7);
        } else {
          setPopupSize(wd, table.getRowHeight() * table.getRowCount());
        }

        show(getTxtSearch(), 0, getTxtSearch().getHeight());
      }
    }
    // return for each item (value) in the list/table the component to
    // render - which is the item itself here
    @Override
    @SuppressWarnings("unchecked")
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      TableItem item = (TableItem) value;

      item.render(table.getWidth(), isSelected);

      int height = Math.max(table.getRowHeight(), item.getPreferredSize().height);
      // view item needs a little more then it preferres
      height += 1;
      if (height != table.getRowHeight(row))
        // note: this calls resizeAndRepaint()
        table.setRowHeight(row, height);
      return item;
    }
 private static void drawSelection(JTable table, int column, Graphics g, final int width) {
   int y = 0;
   final int[] rows = table.getSelectedRows();
   final int height = table.getRowHeight();
   for (int row : rows) {
     final TableCellRenderer renderer = table.getCellRenderer(row, column);
     final Component component =
         renderer.getTableCellRendererComponent(
             table, table.getValueAt(row, column), false, false, row, column);
     g.translate(0, y);
     component.setBounds(0, 0, width, height);
     boolean wasOpaque = false;
     if (component instanceof JComponent) {
       final JComponent j = (JComponent) component;
       if (j.isOpaque()) wasOpaque = true;
       j.setOpaque(false);
     }
     component.paint(g);
     if (wasOpaque) {
       ((JComponent) component).setOpaque(true);
     }
     y += height;
     g.translate(0, -y);
   }
 }
Example #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);
   }
 }
 @Override
 public Rectangle getCellRect(int row, int column, boolean includeSpacing) {
   Rectangle r = super.getCellRect(row, column, includeSpacing);
   int height = table.getRowHeight(row);
   if (getRowHeight(row) != height) setRowHeight(row, height);
   r.height = height;
   return r;
 }
  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);
  }
  @Override
  public int getRowHeight(int row) {
    int rowHeight = main.getRowHeight(row);

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

    return rowHeight;
  }
 private void recomputeNumVisibleRows() {
   Rectangle rect = new Rectangle();
   getBounds(rect);
   int h = table.getRowHeight();
   numVisibleRows = (rect.height + (h - 1)) / h;
   numUsableRows = numVisibleRows - 2;
   scrollBar.setBlockIncrementHP(new BigInteger(Integer.toString(addressSize * (numUsableRows))));
   model.fireTableDataChanged();
   // FIXME: refresh selection
 }
Example #10
0
 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;
 }
  @Override
  public void mouseClicked(MouseEvent e) {
    int column = table.getColumnModel().getColumnIndexAtX(e.getX());
    int row = e.getY() / table.getRowHeight();

    if (row < table.getRowCount() && row >= 0 && column < table.getColumnCount() && column >= 0) {
      Object value = table.getValueAt(row, column);
      if (value != null && value instanceof JButton) ((JButton) value).doClick();
    }
  }
  /* 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;
    }
  }
  /**
   * ctor
   *
   * @param table the table to set the header for
   * @parma width the width (in characters) to size the header column
   */
  public TableRowHeader(JTable table, int width) {
    super(new TableRowHeaderModel(table));
    m_width = width;

    this.table = table;
    setFixedCellHeight(table.getRowHeight());
    setFixedCellWidth(preferredHeaderWidth());

    setCellRenderer(new RowHeaderRenderer(table));
    setFocusable(false);
  }
Example #14
0
 private static int getTableBaseline(JTable table, int height) {
   if (TABLE_LABEL == null) {
     TABLE_LABEL = new JLabel("");
     TABLE_LABEL.setBorder(new EmptyBorder(1, 1, 1, 1));
   }
   JLabel label = TABLE_LABEL;
   label.setFont(table.getFont());
   int rowMargin = table.getRowMargin();
   int baseline = getLabelBaseline(label, table.getRowHeight() - rowMargin);
   return baseline += rowMargin / 2;
 }
Example #15
0
 public void ensureTableFill() {
   Container p = getParent();
   DefaultTableModel dataModel = (DefaultTableModel) dataTable.getModel();
   if (dataTable.getHeight() < p.getHeight()) {
     int newRows = (p.getHeight() - dataTable.getHeight()) / dataTable.getRowHeight();
     dataModel.setRowCount(dataTable.getRowCount() + newRows);
     for (int i = 0; i <= dataTable.getRowCount(); ++i) {
       if (rowHeader.getModel().getElementAt(i) != null)
         ((DefaultListModel) rowHeader.getModel()).add(i, true);
     }
   }
 }
  private void setSizeAndDimensions(
      @NotNull JTable table,
      @NotNull JBPopup popup,
      @NotNull RelativePoint popupPosition,
      @NotNull List<UsageNode> data) {
    JComponent content = popup.getContent();
    Window window = SwingUtilities.windowForComponent(content);
    Dimension d = window.getSize();

    int width = calcMaxWidth(table);
    width = (int) Math.max(d.getWidth(), width);
    Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize();
    width = Math.max((int) headerSize.getWidth(), width);
    width = Math.max(myWidth, width);

    if (myWidth == -1) myWidth = width;
    int newWidth = Math.max(width, d.width + width - myWidth);

    myWidth = newWidth;

    int rowsToShow = Math.min(30, data.size());
    Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
    Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
    dimension = rectangle.getSize();
    Point location = window.getLocation();
    if (!location.equals(rectangle.getLocation())) {
      window.setLocation(rectangle.getLocation());
    }

    if (!data.isEmpty()) {
      TableScrollingUtil.ensureSelectionExists(table);
    }
    table.setSize(dimension);
    // table.setPreferredSize(dimension);
    // table.setMaximumSize(dimension);
    // table.setPreferredScrollableViewportSize(dimension);

    Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize();

    int newHeight =
        (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight())
            + 4 /* invisible borders, margins etc*/;
    Dimension newDim = new Dimension(dimension.width, newHeight);
    window.setSize(newDim);
    window.setMinimumSize(newDim);
    window.setMaximumSize(newDim);

    window.validate();
    window.repaint();
    table.revalidate();
    table.repaint();
  }
  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;
  }
    public static Image createImage(final JTable table, int column) {
      final int height =
          Math.max(20, Math.min(100, table.getSelectedRowCount() * table.getRowHeight()));
      final int width = table.getColumnModel().getColumn(column).getWidth();

      final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2 = (Graphics2D) image.getGraphics();

      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));

      drawSelection(table, column, g2, width);
      return image;
    }
Example #19
0
    @Override
    public void mouseClicked(MouseEvent e) {
      int columna = jTable.getColumnModel().getColumnIndexAtX(e.getX());
      int fila = e.getY() / jTable.getRowHeight();

      if ((fila < jTable.getRowCount() && fila >= 0)
          && (columna < jTable.getColumnCount() && columna >= 0)) {

        if (jTable.getValueAt(fila, columna) instanceof JButton) {
          JButton btn = (JButton) jTable.getValueAt(fila, columna);
          btn.doClick();
        }
      }
    }
Example #20
0
 public java.awt.Component getTableCellRendererComponent(
     javax.swing.JTable table,
     Object color,
     boolean isSelected,
     boolean hasFocus,
     int row,
     int column) {
   return getComponent(
       color,
       isSelected,
       table.getBackground(),
       table.getSelectionBackground(),
       table.getRowHeight(),
       table.getFont());
 }
  /*
   * (non-Javadoc)
   * @see com.vistatec.ocelot.lqi.gui.ColorCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
   */
  @Override
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    Component comp =
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    JTextArea txtArea = new JTextArea();
    if (value != null) {
      txtArea.setText((String) value);
      txtArea.setToolTipText((String) value);
    }
    txtArea.setSize(table.getColumnModel().getColumn(column).getWidth(), table.getRowHeight());
    txtArea.setBackground(comp.getBackground());
    txtArea.setLineWrap(true);
    txtArea.setWrapStyleWord(true);
    return txtArea;
  }
  public ButtonTable(Dimension buttonSize, final JButton... buttons) {
    // setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    JTable table = new JTable();
    table.setTableHeader(null);
    // table.setFillsViewportHeight(true);
    setViewportView(table);

    table.setModel(
        new AbstractTableModel() {

          @Override
          public Object getValueAt(int rowIndex, int columnIndex) {
            return null;
          }

          @Override
          public int getRowCount() {
            return buttons.length;
          }

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

          @Override
          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
          }
        });

    // set all to left align... looks better
    for (JButton button : buttons) {
      button.setHorizontalAlignment(SwingConstants.LEFT);
    }

    CustomTableItemRenderer<JButton> renderer = new CustomTableItemRenderer(buttons);
    TableColumn buttonCol = table.getColumnModel().getColumn(0);
    buttonCol.setCellEditor(renderer);
    buttonCol.setCellRenderer(renderer);
    buttonCol.setWidth(buttonSize.width);
    table.setRowHeight(buttonSize.height);
    setPreferredSize(
        new Dimension(buttonSize.width + 6, table.getRowHeight() * table.getRowCount() + 10));
  }
  private void backBind() {
    status.setText(viewModel.getStatus());
    compute.setEnabled(viewModel.isButtonEnabled());

    monthlyPayment.setText(viewModel.getMonthlyPayment());
    overpaymentWithFees.setText(viewModel.getOverpaymentWithFees());
    overpayment.setText(viewModel.getOverpayment());

    DefaultTableModel model = viewModel.getGraphicOfPayments();
    graphicOfPayments.setModel(model);
    graphicOfPayments.setPreferredSize(
        new Dimension(
            graphicOfPayments.getWidth(), graphicOfPayments.getRowHeight() * model.getRowCount()));

    List<String> log = viewModel.getLog();
    String[] items = log.toArray(new String[log.size()]);
    logList.setListData(items);
  }
  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      e.printStackTrace();
    }

    Action action = new GloballyContextSensitiveAction("selectAll", "selectAll", "selectAll");
    JMenuBar menubar = new JMenuBar();
    JMenu menu = new JMenu("Actions");
    menu.add(action);
    menubar.add(menu);

    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);
    toolbar.setFloatable(true);
    toolbar.add(action);

    JPanel contents = new JPanel();

    String[] listData = new String[] {"item1", "item2", "item3", "item4", "item5            "};
    JList list = new JList(listData);
    contents.add(new JScrollPane(list));

    JTree tree = new JTree();
    tree.setVisibleRowCount(10);
    contents.add(new JScrollPane(tree));

    JTable table = new JTable(new DefaultTableModel(new String[] {"Name", "Type", "Modified"}, 10));
    table.setPreferredScrollableViewportSize(new Dimension(100, 5 * table.getRowHeight()));
    contents.add(new JScrollPane(table));
    contents.add(new JPanel());

    JFrame frame = new JFrame("Globally Context Sensitive Actions - [email protected]");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(menubar);
    frame.getContentPane().add(contents);
    frame.getContentPane().add(toolbar, BorderLayout.NORTH);

    frame.pack();
    frame.show();
  }
Example #25
0
    private void paintStripedBackground(Graphics g) {
      // get the row index at the top of the clip bounds (the first row
      // to paint).
      int rowAtPoint = fTable.rowAtPoint(g.getClipBounds().getLocation());
      // get the y coordinate of the first row to paint. if there are no
      // rows in the table, start painting at the top of the supplied
      // clipping bounds.
      int topY = rowAtPoint < 0 ? g.getClipBounds().y : fTable.getCellRect(rowAtPoint, 0, true).y;

      // create a counter variable to hold the current row. if there are no
      // rows in the table, start the counter at 0.
      int currentRow = rowAtPoint < 0 ? 0 : rowAtPoint;
      while (topY < g.getClipBounds().y + g.getClipBounds().height) {
        int bottomY = topY + fTable.getRowHeight();
        g.setColor(getRowColor(currentRow));
        g.fillRect(g.getClipBounds().x, topY, g.getClipBounds().width, bottomY);
        topY = bottomY;
        currentRow++;
      }
    }
 public InstallationInfo(Configuration configuration, String message) {
   setLayout(new BorderLayout());
   JLabel label = new JLabel(message);
   label.setHorizontalAlignment(SwingConstants.CENTER);
   add(label, BorderLayout.NORTH);
   String[] columns = {"Parameter", "Value"};
   String[][] data = {
     {"Installation Directory", configuration.getParameterValue(Parameter.SERVER_PREFIX)},
     {"Data Directory", configuration.getParameterValue(Parameter.DATA_PREFIX)},
     {"Log Directory", configuration.getParameterValue(Parameter.LOG_PREFIX)},
     {"Hostame", configuration.getParameterValue(Parameter.HOSTNAME)}
   };
   JTable table = new JTable(data, columns);
   JScrollPane container = new JScrollPane(table);
   Dimension size = new Dimension();
   size.width = 600;
   size.height = table.getRowCount() * table.getRowHeight();
   table.setPreferredScrollableViewportSize(size);
   add(container, BorderLayout.CENTER);
   validate();
 }
  public LinearRegressionPanel(Application app, StatDialog statDialog) {

    this.app = app;
    kernel = app.getKernel();
    this.statDialog = statDialog;

    this.setOpaque(true);
    this.setBackground(Color.WHITE);
    this.setLayout(new BorderLayout());

    // north panel with regression equation
    Box northPanel = Box.createVerticalBox();
    northPanel.add(new JLabel(" ---- regresion equation ----"));
    northPanel.add(new JLabel(" ----------------------------"));

    // south panel with additional statistics
    Box southPanel = Box.createVerticalBox();
    southPanel.add(new JLabel(" ---- regresion equation ----"));
    southPanel.add(new JLabel(" ----------------------------"));

    // set up table
    model = new DefaultTableModel();
    headerModel = new DefaultListModel();
    JTable table = new JTable(model);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setGridColor(GeoGebraColorConstants.TABLE_GRID_COLOR);
    table.setShowGrid(true);

    // table row header
    JList rowHeader = new JList(headerModel);
    rowHeader.setFixedCellWidth(50);
    rowHeader.setFixedCellHeight(table.getRowHeight() + table.getRowMargin());
    rowHeader.setCellRenderer(new RowHeaderRenderer(table));

    // add table to scroll pane
    JScrollPane scroll = new JScrollPane(table);
    scroll.setRowHeaderView(rowHeader);

    this.add(scroll, BorderLayout.CENTER);
  }
 /** 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) {
   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);
   }
 }
Example #29
0
  /** Make pick table, DND enabled */
  public JTable makePickTable() {
    this.init();
    try { // following might fail due to a missing method on Mac Classic
      _sorter = new TableSorter(this);
      _table = jmri.util.JTableUtil.sortableDataModel(_sorter);
      _sorter.setTableHeader(_table.getTableHeader());
      _sorter.setColumnComparator(String.class, new jmri.util.SystemNameComparator());
      _table.setModel(_sorter);
    } catch (Throwable e) { // NoSuchMethodError, NoClassDefFoundError and others on early JVMs
      log.error("makePickTable: Unexpected error: " + e);
      _table = new JTable(this);
    }

    _table.setRowSelectionAllowed(true);
    _table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _table.setPreferredScrollableViewportSize(
        new java.awt.Dimension(250, _table.getRowHeight() * 7));
    _table.setDragEnabled(true);
    _table.setTransferHandler(new jmri.util.DnDTableExportHandler());

    _table.getTableHeader().setReorderingAllowed(true);
    _table.setColumnModel(new XTableColumnModel());
    _table.createDefaultColumnsFromModel();
    TableColumnModel columnModel = _table.getColumnModel();

    TableColumn sNameColumnT = columnModel.getColumn(SNAME_COLUMN);
    sNameColumnT.setResizable(true);
    sNameColumnT.setMinWidth(50);
    // sNameColumnT.setMaxWidth(200);

    TableColumn uNameColumnT = columnModel.getColumn(UNAME_COLUMN);
    uNameColumnT.setResizable(true);
    uNameColumnT.setMinWidth(100);
    // uNameColumnT.setMaxWidth(300);

    addMouseListenerToHeader(_table);

    return _table;
  }
Example #30
0
    public Component getTableCellEditorComponent(
        final JTable table,
        final Object value,
        final boolean isSelected,
        final int row,
        final int column) {

      final String boundaryString;
      if (value instanceof PropertyMap) {
        final PropertyMap map = (PropertyMap) value;
        boundaryString = map.getPropertyString(KEY_BOUNDARY_PATH, null);
      } else {
        boundaryString = null;
      }
      final GeneralPath[] geoBoundaryPathes = createGeoBoundaryPathes(boundaryString);
      if (geoBoundaryPathes.length > 0) {
        wmPainter.setWorldMapImage(scaledImage);
        final BufferedImage worldMapImage = wmPainter.createWorldMapImage(geoBoundaryPathes);
        scrollPane.setViewportView(new JLabel(new ImageIcon(worldMapImage)));

        final Color backgroundColor = table.getSelectionBackground();
        scrollPane.setBorder(BorderFactory.createLineBorder(backgroundColor, 3));
        scrollPane.setBackground(backgroundColor);

        // todo: first time scrolling is not good, cause the viewRect has no width and height at
        // this time
        // hack: this is not good, there might be a better solution
        final JViewport viewport = scrollPane.getViewport();
        if (viewport.getWidth() == 0 && viewport.getHeight() == 0) {
          viewport.setSize(
              table.getColumnModel().getColumn(column).getWidth(), table.getRowHeight(row));
        }

        scrollToCenterPath(geoBoundaryPathes[0], viewport);
        return scrollPane;
      } else {
        return null;
      }
    }