Java Code Examples for javax.swing.JLabel#getIconTextGap()

The following examples show how to use javax.swing.JLabel#getIconTextGap() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
public boolean isCellEditable(final EventObject anEvent) {
    if (anEvent instanceof MouseEvent) {
        final MouseEvent event = (MouseEvent) anEvent;
        final int row = treeTable.rowAtPoint(event.getPoint());
        final Rectangle bounds = tree.getRowBounds(row);
        int offset = bounds.x;
        final Object node = tree.getPathForRow(row).getLastPathComponent();
        final boolean leaf = tree.getModel().isLeaf(node);
        final boolean expanded = tree.isExpanded(row);
        final TreeCellRenderer tcr = tree.getCellRenderer();
        final Component treeComponent = tcr.getTreeCellRendererComponent(
                tree, node, true, expanded, leaf, row, false);
        if (treeComponent instanceof JLabel) {
            final JLabel label = (JLabel) treeComponent;

            final Icon icon = label.getIcon();
            if (icon != null) {
                offset += icon.getIconWidth() + label.getIconTextGap();
            }

        }
        if (event.getPoint().x < offset)
            return false;
    }
    return deligate.isCellEditable(anEvent);
}
 
Example 2
Source Project: pumpernickel   File: ThumbnailLabelUI.java    License: MIT License 6 votes vote down vote up
protected void calculateGeometry(JLabel label) {
	FontMetrics fm = label.getFontMetrics(label.getFont());
	String text = label.getText();
	Icon icon = label.getIcon();
	int verticalAlignment = label.getVerticalAlignment();
	int horizontalAlignment = label.getHorizontalAlignment();
	int verticalTextPosition = label.getVerticalTextPosition();
	int horizontalTextPosition = label.getHorizontalTextPosition();
	int textIconGap = label.getIconTextGap();
	viewR.setFrame(0, 0, getViewWidth(label), label.getHeight());
	SwingUtilities.layoutCompoundLabel(fm, text, icon, verticalAlignment,
			horizontalAlignment, verticalTextPosition,
			horizontalTextPosition, viewR, iconRect, textRect, textIconGap);

	textRect.x = label.getWidth() / 2 - textRect.width / 2;
	iconRect.x = label.getWidth() / 2 - iconRect.width / 2;
	iconRect.y = 0;
	textRect.y = iconRect.height + label.getIconTextGap();
}
 
Example 3
Source Project: scelight   File: XTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Positions tool tips exactly over the cell they belong to, also avoids showing empty tool tips (by returning <code>null</code>).
 */
@Override
public Point getToolTipLocation( final MouseEvent event ) {
	// If tool tip is provided by the renderer or the table itself, use default location:
	if ( super.getToolTipText( event ) != null )
		return super.getToolTipLocation( event );
	
	// If no tool tip, return null to prevent displaying an empty tool tip
	if ( getToolTipText( event ) == null )
		return null;
	
	// Else align to the cell:
	final Point point = event.getPoint();
	
	final int column = columnAtPoint( point );
	final int row = rowAtPoint( point );
	
	if ( column < 0 || row < 0 ) // event is not on a cell
		return null;
	
	final Point location = getCellRect( row, column, false ).getLocation();
	// Adjust due to the tool tip border and padding:
	location.x += 1;
	location.y -= 4;
	
	// If the renderer has an icon, take icon size and gap into consideration:
	final Component renderer = prepareRenderer( getCellRenderer( row, column ), row, column );
	if ( renderer instanceof JLabel ) {
		final JLabel l = (JLabel) renderer;
		if ( l.getIcon() != null )
			location.x += l.getIcon().getIconWidth() + l.getIconTextGap();
	}
	
	return location;
}
 
Example 4
Source Project: pumpernickel   File: AquaThumbnailLabelUI.java    License: MIT License 5 votes vote down vote up
@Override
protected void calculateGeometry(JLabel label) {
	super.calculateGeometry(label);
	iconRect.y += 4;
	iconRect.height = 64;
	iconRect.width = 64;
	iconRect.x = label.getWidth() / 2 - 32;

	textRect.y = 72 + label.getIconTextGap();
}
 
Example 5
public InjectedParameterPlaceholderLabel(ConnectionParameterModel param) {
	super(new GridBagLayout());
	GridBagConstraints gbc = new GridBagConstraints();
	JLabel icon = new JLabel("", INJECTED_ICON, JLabel.LEFT);
	add(icon, gbc);
	Font font = icon.getFont();
	String bodyRule = "body { font-family: " + font.getFamily() + "; " +
			"font-size: " + font.getSize() + "pt; }";
	((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule);
	editorPane.setOpaque(false);
	editorPane.setBorder(null);
	editorPane.setEditable(false);
	editorPane.addHyperlinkListener(event -> {
		if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED && event.getURL() != null) {
			RMUrlHandler.openInBrowser(event.getURL());
		}
	});
	gbc.insets.left = icon.getIconTextGap();
	gbc.weightx = 1;
	gbc.fill = GridBagConstraints.HORIZONTAL;
	add(editorPane, gbc);

	valueProviderChanged = (i, o, n) -> updateText(param);
	valueProviderParameterChanged = c -> {
		while (c.next()) {
			for (ValueProviderParameterModel valueProviderParameterModel : c.getAddedSubList()) {
				valueProviderParameterModel.valueProperty().removeListener(valueProviderChanged);
				valueProviderParameterModel.valueProperty().addListener(valueProviderChanged);
			}
		}
		updateText(param);
	};
	param.injectorNameProperty().addListener((i, o, n) -> registerListener(param));
	registerListener(param);
}
 
Example 6
Source Project: netbeans   File: CustomizerPane.java    License: Apache License 2.0 4 votes vote down vote up
public CustomizerPane(JPanel categoryView, CategoryModel categoryModel, ProjectCustomizer.CategoryComponentProvider componentProvider) {
    initComponents();
    this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerPane.class,"AD_CustomizerPane")); // NOI18N
    this.componentProvider = componentProvider;
    fillConstraints = new GridBagConstraints();
    fillConstraints.gridwidth = GridBagConstraints.REMAINDER;
    fillConstraints.gridheight = 1;
    fillConstraints.fill = GridBagConstraints.BOTH;
    fillConstraints.weightx = 1.0;
    fillConstraints.weighty = 1.0;
    categoryModel.addPropertyChangeListener( new CategoryChangeListener() );
    categoryPanel.add( categoryView, fillConstraints );

    errorIcon = new JLabel();
    errorPanel = new JPanel(new BorderLayout(errorIcon.getIconTextGap(), 0)); // cf. BasicLabelUI.layoutCL
    errorPanel.add(errorIcon, BorderLayout.LINE_START);
    errorIcon.setVerticalAlignment(SwingConstants.TOP);
    errorMessageValue = new JTextArea();
    errorMessageValue.setLineWrap(true);
    errorMessageValue.setWrapStyleWord(true);
    errorMessageValue.setBorder(BorderFactory.createEmptyBorder());
    errorMessageValue.setBackground(customizerPanel.getBackground());
    errorMessageValue.setEditable(false);
    errorPanel.add(errorMessageValue, BorderLayout.CENTER);
    
    // put it into under categoryView
    errMessConstraints = new GridBagConstraints();
    errMessConstraints.gridx = 0;
    errMessConstraints.gridy = 1;
    errMessConstraints.gridwidth = 1;
    errMessConstraints.gridheight = 1;
    errMessConstraints.insets = new Insets(12, 0, 0, 0);
    errMessConstraints.fill = GridBagConstraints.HORIZONTAL;
    customizerPanel.add(errorPanel, errMessConstraints);

    /*Preferences prefs = NbPreferences.forModule(org.netbeans.modules.project.uiapi.CustomizerPane.class);
    int paneWidth = prefs.getInt(CUSTOMIZER_DIALOG_WIDTH, 0);
    int paneHeight = prefs.getInt(CUSTOMIZER_DIALOG_HEIGHT, 0);
    if (paneWidth != 0 && paneHeight != 0) {
        previousDimension = new Dimension(paneWidth, paneHeight);
    }*/

    setCategory( categoryModel.getCurrentCategory() );
}