Java Utililty Methods JComponent Properties

List of utility methods to do JComponent Properties

Description

The list of methods to do JComponent Properties are organized into topic(s).

Method

booleanisVisible(JComponent c, Rectangle r)
is Visible
return c.getVisibleRect().contains(r);
booleanisVisible(JComponent comp)
Returns true if the JComponent is visible on the monitor (e.g.
if (comp == null) {
    return false;
Container parent = comp.getParent();
if (parent == null || !(parent instanceof JTabbedPane)) {
    return true;
JTabbedPane tabbedPane = (JTabbedPane) parent;
...
booleanisVisibleOnScreen(final JComponent component)
Checks if is visible on screen.
final Window window = getWindow(component);
if (window != null) {
    return window.isVisible();
return false;
voidregisterComponent(JComponent c)
register Component
InputMap imap = c.getInputMap();
ActionMap amap = c.getActionMap();
boolean removeKeyStroke = false;
KeyStroke[] ks = imap.keys();
if (ks == null || ks.length == 0) {
    imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, 0), "backSlash");
    removeKeyStroke = true;
ToolTipManager.sharedInstance().registerComponent(c);
if (removeKeyStroke) {
    imap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, 0));
voidregisterDataFlavors(JComponent component, DataFlavor... dataFlavors)
register Data Flavors
component.putClientProperty(FLAVORS_CLIENT_PROPERTY, dataFlavors);
voidresetDisplayComponent(JComponent mainComp, JComponent nonDispComp, JComponent newDispComp)
reset Display Component
JComponent[] nonDispComps = { nonDispComp };
resetDisplayComponent(mainComp, nonDispComps, newDispComp);
voidsetComponentEnabled(JComponent component, Boolean isEnabled)
set Component Enabled
if (component == null)
    return;
component.setEnabled(isEnabled);
Component[] components = component.getComponents();
for (Component component1 : components) {
    if (component1 instanceof JComponent) {
        setComponentEnabled((JComponent) component1, isEnabled);
voidsetDirty(JComponent comp, boolean isDirty)
set Dirty
if (comp != null)
    comp.putClientProperty("windowModified", Boolean.valueOf(isDirty));
voidsetGlassPane(JComponent comp, Component glass, boolean visible)
set Glass Pane
Container container = comp.getTopLevelAncestor();
if (container instanceof JFrame) {
    JFrame frame = (JFrame) container;
    frame.setGlassPane(glass);
} else if (container instanceof JDialog) {
    JDialog dialog = (JDialog) container;
    dialog.setGlassPane(glass);
} else {
...
voidsetLegendVisible(JComponent chartUI, boolean visible)
set Legend Visible
JPanel legendPanel = (JPanel) chartUI.getClientProperty("legendPanel"); 
legendPanel.setVisible(visible);
chartUI.doLayout();
chartUI.repaint();