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

The following examples show how to use javax.swing.JTable#setTableHeader() . 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: JSFConfigurationPanelVisual.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void initJsfComponentTableVisualProperties(JTable table) {
    table.setRowSelectionAllowed(true);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    table.setTableHeader(null);

    table.setRowHeight(jsfComponentsTable.getRowHeight() + 4);
    table.setIntercellSpacing(new java.awt.Dimension(0, 0));
    // set the color of the table's JViewport
    table.getParent().setBackground(table.getBackground());
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);

    table.getColumnModel().getColumn(0).setMaxWidth(30);
    if (!panel.isMaven()) {
        table.getColumnModel().getColumn(2).setMaxWidth(100);
    }

}
 
Example 2
Source File: DownloadListView.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
public DownloadListView(JPanel container) {
	model = new DownloadTableModel();
	XDMApp.getInstance().addListener(model);
	table = new JTable(model);
	table.setTableHeader(null);
	table.setDefaultRenderer(DownloadEntry.class, new XDMTableCellRenderer());
	table.setRowHeight(XDMUtils.getScaledInt(70));
	table.setShowGrid(false);
	table.setFillsViewportHeight(true);
	table.setBorder(new EmptyBorder(0, 0, 0, 0));
	table.setDragEnabled(true);
	// table.getSelectionModel().addListSelectionListener(new
	// ListSelectionListener() {
	// @Override
	// public void valueChanged(ListSelectionEvent e) {
	// int selectedRow = e.getFirstIndex();
	// selectedId = model.getIdAt(selectedRow);
	// Logger.log("Selected id1: " + selectedId+" row: "+selectedRow);
	// }
	// });
	//
	// model.addTableModelListener(new TableModelListener() {
	// @Override
	// public void tableChanged(TableModelEvent e) {
	// if(selectedId!=null){
	// int index=model.getIndexOfId(selectedId);
	// Logger.log("Index of "+selectedId+" is: "+index);
	// if(index>-1){
	// table.setRowSelectionInterval(index, index);
	// }
	// }
	// }
	// });

	JScrollPane jsp = new JScrollPane(table);
	jsp.setBorder(new EmptyBorder(0, 0, 0, 0));

	container.add(jsp);
}
 
Example 3
Source File: JSTestDriverCustomizerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initTableVisualProperties(JTable table) {
    table.setRowSelectionAllowed(true);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setTableHeader(null);
    table.setRowHeight(jBrowsersTable.getRowHeight() + 4);        
    table.setIntercellSpacing(new java.awt.Dimension(0, 0));        
    // set the color of the table's JViewport
    table.getParent().setBackground(table.getBackground());
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);
    table.getColumnModel().getColumn(0).setMaxWidth(30);
}
 
Example 4
Source File: UpdateUIRecursionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public UpdateUIRecursionTest() {
    super("UpdateUIRecursionTest");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 400);

     String[] columnNames = {
            "First Name",
            "Last Name",
            "Sport",
            "# of Years",
            "Vegetarian"};

            Object[][] data = {
                {"Mary", "Campione",
                "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                "Pool", new Integer(10), new Boolean(false)}
            };

    JTableHeader tableHeader =  new JTableHeader();
    table = new JTable(data, columnNames);
    table.setTableHeader(tableHeader);
    tableHeader.setDefaultRenderer(this);

    getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);

    setVisible(true);
}
 
Example 5
Source File: AttrTable.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
public AttrTable(Window parent) {
	super(new BorderLayout());
	this.parent = parent;

	titleEnabled = true;
	title = new TitleLabel();
	title.setHorizontalAlignment(SwingConstants.CENTER);
	title.setVerticalAlignment(SwingConstants.CENTER);
	tableModel = new TableModelAdapter(parent, NULL_ATTR_MODEL);
	table = new JTable(tableModel);
	table.setDefaultEditor(Object.class, editor);
	table.setTableHeader(null);
	table.setRowHeight(20);

	Font baseFont = title.getFont();
	int titleSize = Math.round(baseFont.getSize() * 1.2f);
	Font titleFont = baseFont.deriveFont((float) titleSize).deriveFont(Font.BOLD);
	title.setFont(titleFont);
	Color bgColor = new Color(240, 240, 240);
	setBackground(bgColor);
	table.setBackground(bgColor);
	Object renderer = table.getDefaultRenderer(String.class);
	if (renderer instanceof JComponent) {
		((JComponent) renderer).setBackground(Color.WHITE);
	}

	JScrollPane tableScroll = new JScrollPane(table);

	this.add(title, BorderLayout.PAGE_START);
	this.add(tableScroll, BorderLayout.CENTER);
	LocaleManager.addLocaleListener(this);
	localeChanged();
}
 
Example 6
Source File: EditableHeaderJTable.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This method installs the given renderer and editors to the header of the given table. The
 * previous header names will be discarded and replaced by the objects given as initivalValues.
 * These might be changed by the editor components. After this, they might be returned by
 * getHeaderValue.
 */
public static void installEditableHeader(JTable table, TableCellRenderer headerRenderer, TableCellEditor headerEditor,
		Object[] initialValues) {
	TableColumnModel columnModel = table.getColumnModel();
	table.setTableHeader(new EditableTableHeader(columnModel));

	for (int i = 0; i < table.getColumnCount(); i++) {
		EditableTableHeaderColumn col = (EditableTableHeaderColumn) table.getColumnModel().getColumn(i);
		col.setHeaderValue(initialValues[i]);
		col.setHeaderRenderer(headerRenderer);
		col.setHeaderEditor(headerEditor);
	}
}
 
Example 7
Source File: ViewEntity.java    From qupla with Apache License 2.0 4 votes vote down vote up
public ViewEntity(final Dispatcher dispatcher, final String envName)
{
  super(0);

  // this viewer will both join and affect its environment
  // you will see received effects scroll by and data sent
  // from the viewer gets sent immediately to this environment

  this.envName = envName;
  final Environment env = dispatcher.getEnvironment(envName, null);
  join(env);
  affect(env, 0);

  input = new ViewModel(env.typeInfo);
  input.edit = true;
  input.vectors.add(new TritVector(env.typeInfo.size, TritVector.TRIT_ZERO));

  final JTable inTable = new JTable(input);
  updateWidths(inTable, input);
  inTable.setTableHeader(null);

  model = new ViewModel(env.typeInfo);
  final JTable table = new JTable(model);
  updateWidths(table, model);
  table.setFillsViewportHeight(true);
  table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

  //TODO add this code to auto-scroll, but do it only when bottom row is visible
  //    table.addComponentListener(new ComponentAdapter() {
  //      public void componentResized(ComponentEvent e) {
  //        table.scrollRectToVisible(table.getCellRect(table.getRowCount()-1, 0, true));
  //      }
  //    });

  final JScrollPane scroller = new JScrollPane(table);

  final JPanel mainPanel = new JPanel();
  mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
  mainPanel.add(inTable);
  mainPanel.add(scroller);

  frame = new JFrame(envName);
  frame.addWindowListener(windowAdapter);
  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  frame.add(mainPanel);
  frame.pack();
  frame.setVisible(true);
}
 
Example 8
Source File: HeaderPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initComponents() {
    JTable impl = new JTable(new DefaultTableModel(new Object[] { "" }, 0)); // NOI18N
    TableColumnModel colMod = impl.getColumnModel();
    final TableColumn col = colMod.getColumn(0);
    impl.setFocusable(false);
    header = new Header(colMod);
    impl.setTableHeader(header);
    header.setResizingAllowed(false);
    header.setReorderingAllowed(false);

    final TableCellRenderer renderer = header.getDefaultRenderer();
    header.setDefaultRenderer(new TableCellRenderer() {
        public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected, boolean hasFocus,
                int row, int column) {

            Component component = renderer.getTableCellRendererComponent(
                    table, getRendererValue(), isSelected(),
                    isSelected(), row, processMouseEvents() ? 0 : 1);

            setupRenderer(component);

            col.setWidth(header.getWidth());
            return component;
        }
    });

    JScrollPane scroll = new JScrollPane(impl, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
                                               JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) {
        public Dimension getPreferredSize() { return header.getPreferredSize(); }
        public void reshape(int x, int y, int width, int height) {
            header.setPreferredSize(new Dimension(width, height));
            super.reshape(x, y, width, height);
        }
    };
    scroll.setBorder(BorderFactory.createEmptyBorder());
    scroll.setViewportBorder(BorderFactory.createEmptyBorder());

    setLayout(new OverlayLayout(this));
    add(scroll);
}
 
Example 9
Source File: PhpFrameworksPanelVisual.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** This method is called from within the constructor to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    frameworksScrollPane = new JScrollPane();
    frameworksTable = new JTable();
    descriptionLabel = new JLabel();
    separator = new JSeparator();
    configPanel = new JPanel();

    setFocusTraversalPolicy(null);

    frameworksTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    frameworksTable.setShowHorizontalLines(false);
    frameworksTable.setShowVerticalLines(false);
    frameworksTable.setTableHeader(null);
    frameworksScrollPane.setViewportView(frameworksTable);
    frameworksTable.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PhpFrameworksPanelVisual.class, "PhpFrameworksPanelVisual.frameworksTable.AccessibleContext.accessibleName")); // NOI18N
    frameworksTable.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PhpFrameworksPanelVisual.class, "PhpFrameworksPanelVisual.frameworksTable.AccessibleContext.accessibleDescription")); // NOI18N

    descriptionLabel.setText("DUMMY"); // NOI18N

    configPanel.setLayout(new BorderLayout());

    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(Alignment.LEADING)
        .addComponent(separator, GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
        .addGroup(layout.createSequentialGroup()
            .addComponent(descriptionLabel)
            .addContainerGap())
        .addComponent(configPanel, GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
        .addComponent(frameworksScrollPane, GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(frameworksScrollPane, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.RELATED)
            .addComponent(separator, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.RELATED)
            .addComponent(descriptionLabel)
            .addPreferredGap(ComponentPlacement.RELATED)
            .addComponent(configPanel, GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE))
    );

    frameworksScrollPane.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PhpFrameworksPanelVisual.class, "PhpFrameworksPanelVisual.frameworksScrollPane.AccessibleContext.accessibleName")); // NOI18N
    frameworksScrollPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PhpFrameworksPanelVisual.class, "PhpFrameworksPanelVisual.frameworksScrollPane.AccessibleContext.accessibleDescription")); // NOI18N
    descriptionLabel.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PhpFrameworksPanelVisual.class, "PhpFrameworksPanelVisual.descriptionLabel.AccessibleContext.accessibleName")); // NOI18N
    configPanel.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PhpFrameworksPanelVisual.class, "PhpFrameworksPanelVisual.configPanel.AccessibleContext.accessibleName")); // NOI18N
    configPanel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PhpFrameworksPanelVisual.class, "PhpFrameworksPanelVisual.configPanel.AccessibleContext.accessibleDescription")); // NOI18N

    getAccessibleContext().setAccessibleName(NbBundle.getMessage(PhpFrameworksPanelVisual.class, "PhpFrameworksPanelVisual.AccessibleContext.accessibleName")); // NOI18N
    getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PhpFrameworksPanelVisual.class, "PhpFrameworksPanelVisual.AccessibleContext.accessibleDescription")); // NOI18N
}
 
Example 10
Source File: HeaderPanel.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private void initComponents() {
    JTable impl = new JTable(new DefaultTableModel(new Object[] { "" }, 0)); // NOI18N
    TableColumnModel colMod = impl.getColumnModel();
    final TableColumn col = colMod.getColumn(0);
    impl.setFocusable(false);
    header = new Header(colMod);
    impl.setTableHeader(header);
    header.setResizingAllowed(false);
    header.setReorderingAllowed(false);

    final TableCellRenderer renderer = header.getDefaultRenderer();
    header.setDefaultRenderer(new TableCellRenderer() {
        public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected, boolean hasFocus,
                int row, int column) {

            Component component = renderer.getTableCellRendererComponent(
                    table, getRendererValue(), isSelected(),
                    isSelected(), row, processMouseEvents() ? 0 : 1);

            setupRenderer(component);

            col.setWidth(header.getWidth());
            return component;
        }
    });

    JScrollPane scroll = new JScrollPane(impl, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
                                               JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) {
        public Dimension getPreferredSize() { return header.getPreferredSize(); }
        public void reshape(int x, int y, int width, int height) {
            header.setPreferredSize(new Dimension(width, height));
            super.reshape(x, y, width, height);
        }
    };
    scroll.setBorder(BorderFactory.createEmptyBorder());
    scroll.setViewportBorder(BorderFactory.createEmptyBorder());

    setLayout(new OverlayLayout(this));
    add(scroll);
}
 
Example 11
Source File: HeaderPanel.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private void initComponents() {
    JTable impl = new JTable(new DefaultTableModel(new Object[] { "" }, 0)); // NOI18N
    TableColumnModel colMod = impl.getColumnModel();
    final TableColumn col = colMod.getColumn(0);
    impl.setFocusable(false);
    header = new Header(colMod);
    impl.setTableHeader(header);
    header.setResizingAllowed(false);
    header.setReorderingAllowed(false);

    final TableCellRenderer renderer = header.getDefaultRenderer();
    header.setDefaultRenderer(new TableCellRenderer() {
        public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected, boolean hasFocus,
                int row, int column) {

            Component component = renderer.getTableCellRendererComponent(
                    table, getRendererValue(), isSelected(),
                    isSelected(), row, processMouseEvents() ? 0 : 1);

            setupRenderer(component);

            col.setWidth(header.getWidth());
            return component;
        }
    });

    JScrollPane scroll = new JScrollPane(impl, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
                                               JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) {
        public Dimension getPreferredSize() { return header.getPreferredSize(); }
        public void reshape(int x, int y, int width, int height) {
            header.setPreferredSize(new Dimension(width, height));
            super.reshape(x, y, width, height);
        }
    };
    scroll.setBorder(BorderFactory.createEmptyBorder());
    scroll.setViewportBorder(BorderFactory.createEmptyBorder());

    setLayout(new OverlayLayout(this));
    add(scroll);
}
 
Example 12
Source File: SorterDialog.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Creates JPanel with checkboxes of different things to sort by. List is:
 * priority, class, package, category, bugcode, status, and type.
 */
private JPanel createSorterPane() {
    JPanel insidePanel = new JPanel();
    insidePanel.setLayout(new GridBagLayout());
    preview = new JTableHeader();
    Sortables[] sortables = MainFrame.getInstance().getAvailableSortables();
    preview.setColumnModel(new SorterTableColumnModel(sortables));

    for (Sortables s : sortables) {
        if (s != Sortables.DIVIDER) {
            checkBoxSortList.add(new SortableCheckBox(s));
        }
    }

    setSorterCheckBoxes();

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 1;
    gbc.insets = new Insets(2, 5, 2, 5);
    insidePanel.add(new JLabel("<html><h2>1. Choose bug properties"), gbc);
    insidePanel.add(new CheckBoxList<>(checkBoxSortList.toArray(new JCheckBox[checkBoxSortList.size()])), gbc);

    JTable t = new JTable(new DefaultTableModel(0, sortables.length));
    t.setTableHeader(preview);
    preview.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
    insidePanel.add(new JLabel("<html><h2>2. Drag and drop to change grouping priority"), gbc);
    insidePanel.add(createAppropriatelySizedScrollPane(t), gbc);

    sortApply = new JButton(edu.umd.cs.findbugs.L10N.getLocalString("dlg.apply_btn", "Apply"));
    sortApply.addActionListener(e -> {
        MainFrame.getInstance().getSorter().createFrom((SorterTableColumnModel) preview.getColumnModel());
        ((BugTreeModel) MainFrame.getInstance().getTree().getModel()).checkSorter();
        SorterDialog.this.dispose();
    });
    gbc.fill = GridBagConstraints.NONE;
    insidePanel.add(sortApply, gbc);

    JPanel sorter = new JPanel();
    sorter.setLayout(new BorderLayout());
    sorter.add(new JScrollPane(insidePanel), BorderLayout.CENTER);

    return sorter;
}