Java Code Examples for javax.swing.JTable#setSize()

The following examples show how to use javax.swing.JTable#setSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskList.java    From swift-k with Apache License 2.0 8 votes vote down vote up
public TaskList(TaskHandler handler) {
	this();
	this.handler = handler;
	model = new SingleHandlerTaskModel(handler);
	table = new JTable(model);
	table.setAutoCreateColumnsFromModel(true);
	table.setDefaultRenderer(String.class, new DefaultTableCellRenderer());
	getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
	update(0,0);
	table.setSize(640,200);
	table.setPreferredSize(new Dimension(640, 200));
	pack();
}
 
Example 2
Source File: ETableColumn.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Forces the table to resize given column.
 */
private void resize(int newWidth, JTable table) {
    int oldWidth = getWidth();
    JTableHeader header = table.getTableHeader();
    if (header == null) {
        return;
    }
    header.setResizingColumn(this);
    final int oldMin = getMinWidth();
    final int oldMax = getMaxWidth();
    setMinWidth(newWidth);
    setMaxWidth(newWidth);
    setWidth(newWidth);
    // The trick is to restore the original values
    // after the table has be layouted. During layout this column
    // has fixed width (by setting min==max==preffered)
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            setMinWidth(oldMin);
            setMaxWidth(oldMax);
        }
    });
    Container container;
    if ((header.getParent() == null) ||
            ((container = header.getParent().getParent()) == null) ||
            !(container instanceof JScrollPane)) {
        header.setResizingColumn(null);
        return;
    }
    
    if (!container.getComponentOrientation().isLeftToRight() &&
            ! header.getComponentOrientation().isLeftToRight()) {
        if (table != null) {
            JViewport viewport = ((JScrollPane)container).getViewport();
            int viewportWidth = viewport.getWidth();
            int diff = newWidth - oldWidth;
            int newHeaderWidth = table.getWidth() + diff;
            
            /* Resize a table */
            Dimension tableSize = table.getSize();
            tableSize.width += diff;
            table.setSize(tableSize);
            
            /* If this table is in AUTO_RESIZE_OFF mode and
             * has a horizontal scrollbar, we need to update
             * a view's position.
             */
            if ((newHeaderWidth >= viewportWidth) &&
                    (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                Point p = viewport.getViewPosition();
                p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
                viewport.setViewPosition(p);
            }
        }
    }
    header.setResizingColumn(null);
}
 
Example 3
Source File: DrawGridLinesTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTableGridLines() {

        TableModel dataModel = new AbstractTableModel() {
            public int getColumnCount() {
                return 10;
            }

            public int getRowCount() {
                return 10;
            }

            public Object getValueAt(int row, int col) {
                return " ";
            }
        };

        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setOpaque(true);
        r.setBackground(CELL_RENDERER_BACKGROUND_COLOR);

        JTable table = new JTable(dataModel);
        table.setSize(WIDTH, HEIGHT);
        table.setDefaultRenderer(Object.class, r);
        table.setGridColor(GRID_COLOR);
        table.setShowGrid(true);
        table.setShowHorizontalLines(true);
        table.setShowVerticalLines(true);
        table.setBackground(TABLE_BACKGROUND_COLOR);

        checkTableGridLines(table);
    }
 
Example 4
Source File: DrawGridLInesTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTableGridLines() {

        TableModel dataModel = new AbstractTableModel() {
            public int getColumnCount() {
                return 10;
            }

            public int getRowCount() {
                return 10;
            }

            public Object getValueAt(int row, int col) {
                return " ";
            }
        };

        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setOpaque(true);
        r.setBackground(CELL_RENDERER_BACKGROUND_COLOR);

        JTable table = new JTable(dataModel);
        table.setSize(WIDTH, HEIGHT);
        table.setDefaultRenderer(Object.class, r);
        table.setGridColor(GRID_COLOR);
        table.setShowGrid(true);
        table.setShowHorizontalLines(true);
        table.setShowVerticalLines(true);
        table.setBackground(TABLE_BACKGROUND_COLOR);

        checkTableGridLines(table);
    }
 
Example 5
Source File: TaskList.java    From swift-k with Apache License 2.0 5 votes vote down vote up
public TaskList(List handlers) {
	this();
	this.handlers = handlers;
	model = new MultipleHandlerTaskModel(handlers);
	table = new JTable(model);
	table.setAutoCreateColumnsFromModel(true);
	table.setDefaultRenderer(String.class, new DefaultTableCellRenderer());
	getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
	update(0,0);
	table.setSize(640,200);
	table.setPreferredSize(new Dimension(640, 200));
	pack();
}
 
Example 6
Source File: PortMapperView.java    From portmapper with GNU General Public License v3.0 5 votes vote down vote up
private JComponent getMappingsPanel() {
    // Mappings panel

    final ActionMap actionMap = this.getContext().getActionMap(this.getClass(), this);

    tableModel = new PortMappingsTableModel(app);
    mappingsTable = new JTable(tableModel);
    mappingsTable.setAutoCreateRowSorter(true);
    mappingsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    mappingsTable.setSize(new Dimension(400, 100));
    mappingsTable.getSelectionModel().addListSelectionListener(
            e -> firePropertyChange(PROPERTY_MAPPING_SELECTED, false, isMappingSelected()));

    final JScrollPane mappingsTabelPane = new JScrollPane();
    mappingsTabelPane.setViewportView(mappingsTable);

    final JPanel mappingsPanel = new JPanel(new MigLayout("", "[fill,grow]", "[grow,fill][]"));
    mappingsPanel.setName("port_mappings");
    final Border panelBorder = BorderFactory
            .createTitledBorder(app.getResourceMap().getString("mainFrame.port_mappings.title"));
    mappingsPanel.setBorder(panelBorder);
    mappingsPanel.add(mappingsTabelPane, "height 100::, span 2, wrap");

    mappingsPanel.add(new JButton(actionMap.get(ACTION_REMOVE_MAPPINGS)), "");
    mappingsPanel.add(new JButton(actionMap.get(ACTION_UPDATE_PORT_MAPPINGS)), "wrap");
    return mappingsPanel;
}
 
Example 7
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 8
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
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();
}