Java Code Examples for javax.swing.JComponent#setToolTipText()

The following examples show how to use javax.swing.JComponent#setToolTipText() . 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 check out the related API usage on the sidebar.
Example 1
Source Project: opt4j   File: QTable.java    License: MIT License 6 votes vote down vote up
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
	final Component c = super.prepareRenderer(renderer, row, column);
	if (c instanceof JComponent) {
		final JComponent jc = (JComponent) c;

		Object value = getValueAt(row, column);

		if (value != null) {
			final String text = value.toString();
			final int length = jc.getFontMetrics(jc.getFont()).stringWidth(text);

			if (getColumnModel().getColumn(column).getWidth() < length) {
				jc.setToolTipText(text);
			} else {
				jc.setToolTipText(null);
			}
		}

	}
	return c;
}
 
Example 2
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    JComponent comp = (JComponent) super.getTableCellRendererComponent(
            table, value, isSelected, hasFocus, row, col);
    List<Integer> dupList = getDuplicate(row);
    if (!dupList.isEmpty()) {
        comp.setForeground(errorColor);
        comp.setToolTipText("Duplicate with Step " + dupList);
    } else if (col == ExecutionStep.HEADERS.Status.getIndex()) {
        if ("Passed".equals(value)) {
            comp.setForeground(Color.GREEN.darker());
        } else if ("Failed".equals(value)) {
            comp.setForeground(errorColor);
        } else {
            comp.setForeground(table.getForeground());
        }
    } else {
        comp.setForeground(table.getForeground());
        comp.setToolTipText(null);
    }
    return comp;
}
 
Example 3
Source Project: netbeans   File: SummaryCellRenderer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean mouseMoved(Point p, JComponent component) {
    if (bounds != null && bounds.contains(p)) {
        component.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        int i = item.getNextFilesToShowCount();
        String tooltip;
        if (i > 0) {
            tooltip = NbBundle.getMessage(SummaryCellRenderer.class, "MSG_ShowMoreFiles", i); //NOI18N
        } else {
            tooltip = NbBundle.getMessage(SummaryCellRenderer.class, "MSG_ShowAllFiles"); //NOI18N
        }
        component.setToolTipText(tooltip);
        return true;
    }
    return false;
}
 
Example 4
Source Project: jts   File: GuiUtil.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Changes the tooltip text of the JComponent to be multiline HTML.
 */
public static void formatTooltip(JComponent jcomponent) {
    String tip = jcomponent.getToolTipText();
    if (tip == null || tip.length() == 0)
        return;
    if (tip.toLowerCase().indexOf("<html>") > -1)
        return;
    tip = StringUtil.wrap(tip, 50);
    tip = StringUtil.replaceAll(tip, "\n", "<p>");
    tip = "<html>" + tip + "</html>";
    jcomponent.setToolTipText(tip);
}
 
Example 5
protected void createField(String label, JComponent tf, String tooltip) {
    JLabel jl = new JLabel(label+": ");
    jl.setToolTipText(tooltip);
    tf.setToolTipText(tooltip);
    pLabels.add(jl);
    JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
    p.add(tf);
    pFields.add(p);
}
 
Example 6
Source Project: netbeans   File: TableView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Component oc = orig.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (tooltip == null) {
        tooltip = getShortDescription(value.toString());
    }
    if ((tooltip != null) && (oc instanceof JComponent)) {
        JComponent jc = (JComponent)oc;
        jc.setToolTipText(tooltip);
    }
    return oc;
}
 
Example 7
Source Project: netbeans   File: OutlineView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Component oc = orig.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (tooltip == null) {
        tooltip = getShortDescription (value.toString ());
    }
    if ((tooltip != null) && (oc instanceof JComponent)) {
        JComponent jc = (JComponent)oc;
        jc.setToolTipText(tooltip);
    }
    return oc;
}
 
Example 8
private void addItem(
    final String labelText, final JComponent item, final String tooltip, final int rowsNeeded) {
  // Create the label and its constraints
  final JLabel label = new JLabel(labelText);
  final GridBagConstraints labelConstraints = new GridBagConstraints();
  labelConstraints.gridx = labelColumn;
  labelConstraints.gridy = nextRow;
  labelConstraints.gridheight = rowsNeeded;
  labelConstraints.insets = new Insets(10, 10, 0, 0);
  labelConstraints.anchor = GridBagConstraints.NORTHEAST;
  labelConstraints.fill = GridBagConstraints.NONE;
  add(label, labelConstraints);
  // Add the component with its constraints
  final GridBagConstraints itemConstraints = new GridBagConstraints();
  itemConstraints.gridx = labelColumn + 1;
  itemConstraints.gridy = nextRow;
  itemConstraints.gridheight = rowsNeeded;
  itemConstraints.insets = new Insets(10, 10, 0, 10);
  itemConstraints.weightx = 1.0;
  itemConstraints.anchor = GridBagConstraints.WEST;
  itemConstraints.fill = GridBagConstraints.NONE;
  add(item, itemConstraints);
  if (tooltip != null && tooltip.length() > 0) {
    label.setToolTipText(tooltip);
    item.setToolTipText(tooltip);
  }
  nextRow += rowsNeeded;
}
 
Example 9
/**
 * Sets the tooltip text on the specified label based on the passed parameters.
 *
 * @param component The component whose tooltip text property will be set.
 * @param unitType The type of unit.
 * @param player The owner of the unit.
 * @param count The number of units.
 */
public static void setUnitTooltip(
    final JComponent component,
    final UnitType unitType,
    final GamePlayer player,
    final int count) {
  final String text = getTooltipTextForUnit(unitType, player, count);
  component.setToolTipText("<html>" + text + "</html>");
}
 
Example 10
Source Project: netbeans   File: TooltipWindow.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean mouseMoved (Point p, JComponent component) {
    if (bounds != null && bounds.contains(p)) {
        component.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        component.setToolTipText(Bundle.CTL_AnnotationBar_action_showCommit(revision));
        return true;
    }
    return false;
}
 
Example 11
Source Project: netbeans   File: SummaryCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean mouseMoved (Point p, JComponent component) {
    if (bounds != null && component.getToolTipText() == null) {
        for (Rectangle b : bounds) {
            if (b.contains(p)) {
                component.setToolTipText(text);
                return true;
            }
        }
    }
    return false;
}
 
Example 12
Source Project: netbeans   File: SummaryCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean mouseMoved(Point p, JComponent component) {
    if (bounds != null && bounds.contains(p)) {
        component.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        component.setToolTipText(NbBundle.getMessage(SummaryCellRenderer.class, "MSG_ShowLessFiles")); //NOI18N
        return true;
    }
    return false;
}
 
Example 13
Source Project: netbeans   File: SummaryCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean mouseMoved(Point p, JComponent component) {
    if (bounds != null && bounds.contains(p)) {
        component.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        if (item.revisionExpanded) {
            component.setToolTipText(NbBundle.getMessage(SummaryCellRenderer.class, "MSG_CollapseRevision")); //NOI18N
        } else {
            component.setToolTipText(NbBundle.getMessage(SummaryCellRenderer.class, "MSG_ExpandRevision")); //NOI18N
        }
        return true;
    }
    return false;
}
 
Example 14
Source Project: netbeans   File: SummaryCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean mouseMoved(Point p, JComponent component) {
    if (bounds != null && bounds.contains(p)) {
        component.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        component.setToolTipText(NbBundle.getMessage(SummaryCellRenderer.class, "MSG_ShowActions")); //NOI18N
        return true;
    }
    return false;
}
 
Example 15
protected void configureFileChooser(final SnapFileChooser fileChooser, final ProductSceneView view,
                                    String imageBaseName) {
    fileChooser.setDialogTitle(SnapApp.getDefault().getInstanceName() + " - " + "Export Image"); /*I18N*/
    if (view.isRGB()) {
        fileChooser.setCurrentFilename(imageBaseName + "_RGB");
    } else {
        fileChooser.setCurrentFilename(imageBaseName + "_" + view.getRaster().getName());
    }

    final JPanel regionPanel = new JPanel(new GridLayout(2, 1));
    regionPanel.setBorder(BorderFactory.createTitledBorder("Image Region"));
    buttonFullRegion = new JRadioButton("Full scene");
    buttonFullRegion.setToolTipText("Use the image boundaries of the source data");
    buttonFullRegion.setActionCommand(AC_FULL_REGION);
    buttonVisibleRegion = new JRadioButton("View region");
    buttonVisibleRegion.setToolTipText("Use the image boundaries of the view window");
    buttonVisibleRegion.setActionCommand(AC_VIEW_REGION);
    regionPanel.add(buttonVisibleRegion);
    regionPanel.add(buttonFullRegion);

    buttonGroupRegion = new ButtonGroup();
    buttonGroupRegion.add(buttonVisibleRegion);
    buttonGroupRegion.add(buttonFullRegion);

    final JPanel resolutionPanel = new JPanel(new GridLayout(3, 1));
    resolutionPanel.setBorder(BorderFactory.createTitledBorder("Image Resolution"));
    buttonViewResolution = new JRadioButton("View resolution");
    buttonViewResolution.setToolTipText("Use the resolution of the view window as it is on the computer screen");
    buttonViewResolution.setActionCommand(AC_VIEW_RES);
    buttonFullResolution = new JRadioButton("Full resolution");
    buttonFullResolution.setToolTipText("Use the resolution of the source data");
    buttonFullResolution.setActionCommand(AC_FULL_RES);
    buttonUserResolution = new JRadioButton("User resolution");
    buttonUserResolution.setToolTipText("Use a custom resolution set by the user");
    buttonUserResolution.setActionCommand(AC_USER_RES);
    resolutionPanel.add(buttonViewResolution);
    resolutionPanel.add(buttonFullResolution);
    resolutionPanel.add(buttonUserResolution);

    buttonGroupResolution = new ButtonGroup();
    buttonGroupResolution.add(buttonViewResolution);
    buttonGroupResolution.add(buttonFullResolution);
    buttonGroupResolution.add(buttonUserResolution);

    sizeComponent = new SizeComponent(view);
    JComponent sizePanel = sizeComponent.createComponent();
    sizePanel.setBorder(BorderFactory.createTitledBorder("Image Dimension")); /*I18N*/
    sizePanel.setToolTipText("Fixed ratio is automatically applied to width and height");

    final JPanel accessory = new JPanel();
    accessory.setLayout(new BoxLayout(accessory, BoxLayout.Y_AXIS));
    accessory.add(regionPanel);
    accessory.add(resolutionPanel);
    accessory.add(sizePanel);

    fileChooser.setAccessory(accessory);
    buttonVisibleRegion.addActionListener(e -> updateComponents(e.getActionCommand()));
    buttonFullRegion.addActionListener(e -> updateComponents(e.getActionCommand()));
    buttonViewResolution.addActionListener(e -> updateComponents(e.getActionCommand()));
    buttonFullResolution.addActionListener(e -> updateComponents(e.getActionCommand()));
    buttonUserResolution.addActionListener(e -> updateComponents(e.getActionCommand()));
    updateComponents(PSEUDO_AC_INIT);

}
 
Example 16
/**
 * Create the transparency mode selector row.
 *
 * @return component holding the selector and the related label
 */
private JComponent createTransparencySelector() {
	JComponent row = SBoxLayout.createContainer(SBoxLayout.HORIZONTAL, SBoxLayout.COMMON_PADDING);
	JLabel label = new JLabel("Transparency mode:");
	row.add(label);
	final JComboBox<String> selector = new JComboBox<>();
	final String[][] data = {
			{"Automatic (default)", "auto", "The appropriate mode is decided automatically based on the system speed."},
			{"Full translucency", "translucent", "Use semitransparent images where available. This is slow on some systems."},
			{"Simple transparency", "bitmask", "Use simple transparency where parts of the image are either fully transparent or fully opaque.<p>Use this setting on old computers, if the game is unresponsive otherwise."}
	};

	// Convenience mapping for getting the data rows from either short or
	// long names
	final Map<String, String[]> desc2data = new HashMap<String, String[]>();
	Map<String, String[]> key2data = new HashMap<String, String[]>();

	for (String[] s : data) {
		// fill the selector...
		selector.addItem(s[0]);
		// ...and prepare the convenience mappings in the same step
		desc2data.put(s[0], s);
		key2data.put(s[1], s);
	}

	// Find out the current option
	final WtWindowManager wm = WtWindowManager.getInstance();
	String currentKey = wm.getProperty(TRANSPARENCY_PROPERTY, "auto");
	String[] currentData = key2data.get(currentKey);
	if (currentData == null) {
		// invalid value; force the default
		currentData = key2data.get("auto");
	}
	selector.setSelectedItem(currentData[0]);
	selector.setRenderer(new TooltippedRenderer(data));

	selector.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			Object selected = selector.getSelectedItem();
			String[] selectedData = desc2data.get(selected);
			wm.setProperty(TRANSPARENCY_PROPERTY, selectedData[1]);
			ClientSingletonRepository.getUserInterface().addEventLine(new EventLine("",
					"The new transparency mode will be used the next time you start the game client.",
					NotificationType.CLIENT));
		}
	});
	row.add(selector);

	StringBuilder toolTip = new StringBuilder("<html>The transparency mode used for the graphics. The available options are:<dl>");
	for (String[] optionData : data) {
		toolTip.append("<dt><b>");
		toolTip.append(optionData[0]);
		toolTip.append("</b></dt>");
		toolTip.append("<dd>");
		toolTip.append(optionData[2]);
		toolTip.append("</dd>");
	}
	toolTip.append("</dl></html>");
	row.setToolTipText(toolTip.toString());
	selector.setToolTipText(toolTip.toString());

	return row;
}
 
Example 17
Source Project: netbeans   File: CategoryList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Component getListCellRendererComponent (JList list,
        Object value,
        int index,
        boolean isSelected,
        boolean cellHasFocus) {
    CategoryList categoryList = (CategoryList) list;
    boolean showNames = categoryList.getShowNames ();
    int iconSize = categoryList.getIconSize ();
    
    JComponent rendererComponent = toolbar != null ? toolbar : button;

    Item item = (Item) value;
    Image icon = item.getIcon (iconSize);
    if (icon != null) {
        button.setIcon (new ImageIcon (icon));
    }

    button.setText (showNames ? item.getDisplayName () : null);
    rendererComponent.setToolTipText( item.getShortDescription() ); // NOI18N

    button.setSelected (isSelected);
    //if (defaultBorder == null) { // Windows or Metal
        // let the toolbar UI render the button according to "rollover"
        button.getModel ().setRollover (index == categoryList.rolloverIndex && !isSelected);
    /*} else { // Mac OS X and others - set the border explicitly
        button.setBorder (defaultBorder);
    }*/
    button.setBorderPainted ((index == categoryList.rolloverIndex) || isSelected);

    button.setHorizontalAlignment (showNames ? SwingConstants.LEFT : SwingConstants.CENTER);
    button.setHorizontalTextPosition (SwingConstants.RIGHT);
    button.setVerticalTextPosition (SwingConstants.CENTER);
    Color c = new Color(UIManager.getColor("Tree.background").getRGB()); //NOI18N
    if( isNimbus )
        toolbar.setBackground(c);
    if( isGTK )
        button.setBackground(c);

    return rendererComponent;
}
 
Example 18
Source Project: scelight   File: LSettingsGui.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Checks if editing the specified setting requires registration and if so and registration is not OK, disables the specified setting component and sets a
 * tool tip to it stating that editing it requires registration.
 * 
 * @param setting setting to be checked
 * @param settingComponent setting component to be disabled if registration requirement is not met
 */
public static void checkRegistration( final ISetting< ? > setting, final JComponent settingComponent ) {
	if ( setting.getViewHints().isEditRequiresRegistration() && !LEnv.REG_MANAGER.isOk() ) {
		settingComponent.setEnabled( false );
		settingComponent.setToolTipText( "Editing / changing this field requires registration!" );
	}
}
 
Example 19
Source Project: freecol   File: Utility.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Localize the tool tip message for a JComponent.
 *
 * @param comp The {@code JComponent} to localize.
 * @param template The {@code StringTemplate} to use.
 */
public static void localizeToolTip(JComponent comp,
                                   StringTemplate template) {
    comp.setToolTipText(Messages.message(template));
}
 
Example 20
Source Project: magarena   File: HintPanel.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 *
 * @param aComponent
 * @param text : tooltip text (can use html).
 */
public void addHintSource(JComponent aComponent, String text) {
    aComponent.setToolTipText(text);
    aComponent.addMouseListener(tooltipMouseAdapter);
}