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

The following examples show how to use javax.swing.JTable#getParent() . 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: SchemaGraphComponent.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
public int getColumnLocation(mxCellState edge, mxCellState terminal,
		int column)
{
	Component[] c = components.get(terminal.getCell());
	int y = 0;

	if (c != null)
	{
		for (int i = 0; i < c.length; i++)
		{
			if (c[i] instanceof JTableRenderer)
			{
				JTableRenderer vertex = (JTableRenderer) c[i];

				JTable table = vertex.table;
				JViewport viewport = (JViewport) table.getParent();
				double dy = -viewport.getViewPosition().getY();
				y = (int) Math.max(terminal.getY() + 22, terminal.getY()
						+ Math.min(terminal.getHeight() - 20, 30 + dy
								+ column * 16));
			}
		}
	}

	return y;
}
 
Example 2
Source File: MPrinter.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * Choix du fichier pour un export.
 *
 * @return File
 * @param table
 *           JTable
 * @param extension
 *           String
 * @throws IOException
 *            Erreur disque
 */
protected File chooseFile(final JTable table, final String extension) throws IOException {
	final JFileChooser myFileChooser = getFileChooser();

	final MExtensionFileFilter filter = new MExtensionFileFilter(extension);
	myFileChooser.addChoosableFileFilter(filter);

	String title = buildTitle(table);
	if (title != null) {
		// on remplace par des espaces les caractères interdits dans les noms de fichiers : \ / : * ? " < > |
		final String notAllowed = "\\/:*?\"<>|";
		final int notAllowedLength = notAllowed.length();
		for (int i = 0; i < notAllowedLength; i++) {
			title = title.replace(notAllowed.charAt(i), ' ');
		}
		myFileChooser.setSelectedFile(new File(title));
	}
	// l'extension sera ajoutée ci-dessous au nom du fichier

	try {
		final Component parent = table.getParent() != null ? table.getParent() : table;
		if (myFileChooser.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
			String fileName = myFileChooser.getSelectedFile().getCanonicalPath();
			if (!fileName.endsWith('.' + extension)) {
				fileName += '.' + extension; // NOPMD
			}

			return new File(fileName);
		}
		return null;
	} finally {
		myFileChooser.removeChoosableFileFilter(filter);
	}
}
 
Example 3
Source File: SeaGlassTableUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link Border} that paints any empty space to the right of the
 * last column header in the given {@link JTable}'s {@link JTableHeader}.
 *
 * @param  table DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private static Border createTableHeaderEmptyColumnPainter(final JTable table) {
    return new AbstractBorder() {
        @Override
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            // if this JTableHeader is parented in a JViewport, then paint
            // the table header background to the right of the last column
            // if neccessary.
            Container viewport = table.getParent();

            if ((viewport instanceof JViewport) && table.getWidth() < viewport.getWidth()) {
                int startX           = table.getWidth();
                int emptyColumnWidth = viewport.getWidth() - table.getWidth();

                TableCellRenderer renderer  = table.getTableHeader().getDefaultRenderer();
                // Rossi: Fix for indexoutofbounds exception: A try catch might be good too?
                Component         component = renderer.getTableCellRendererComponent(table, "", false, false, 0, table.getColumnCount()-1);

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

                ((JComponent) component).setOpaque(true);
                CELL_RENDER_PANE.paintComponent(g, component, null, startX, 0, emptyColumnWidth + 1,
                                                table.getTableHeader().getHeight(), true);
            }
        }
    };
}
 
Example 4
Source File: SeaGlassTableUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * DOCUMENT ME!
 *
 * @param  table DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private static PropertyChangeListener createAncestorPropertyChangeListener(final JTable table) {
    return new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (table.getParent() instanceof JViewport && table.getParent().getParent() instanceof JScrollPane) {
                table.getParent().repaint();
            }
        }
    };
}
 
Example 5
Source File: TableUtil.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
/**
 * Creats a row header for the given table. The row number is displayed to
 * the left of the table ( starting with row 1).
 *
 * @param table       the table to create the row header for
 * @param headerWidth the number of characters to size the header
 */
public static TableRowHeader setRowHeader(JTable table, int headerWidth) {
    TableRowHeader result = null;
    Container p = table.getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            result = new TableRowHeader(table);
            scrollPane.setRowHeaderView(result);
        }
    }
    return result;
}
 
Example 6
Source File: TableUtil.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
/**
 * Creates row header for table with row number (starting with 1) displayed.
 */
public static void removeRowHeader(JTable table) {
    Container p = table.getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            scrollPane.setRowHeader(null);
        }
    }
}
 
Example 7
Source File: TableRowUtilities.java    From swing_library with MIT License 4 votes vote down vote up
public TableListener(JTable rowHeadersTable, JTable userTable) {
	this.userTable = userTable;
	this.rowHeadersTable = rowHeadersTable;

	Container p = userTable.getParent();
	userTableViewPort = (JViewport) p;

	Container p2 = rowHeadersTable.getParent();
	rowHeadersViewPort = (JViewport) p2;

	Point newPosition = userTableViewPort.getViewPosition();
	rowHeadersViewPort.setViewPosition(newPosition);

	// userTableViewPort.setViewPosition(newPosition);

	rowHeadersTable.getSelectionModel().addListSelectionListener(this);
	userTable.getSelectionModel().addListSelectionListener(this);

}