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

The following examples show how to use javax.swing.JComponent#addComponentListener() . 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
/**
 * Creates a progress bar.
 * 
 * @param parent progress bar's parent. The horizontal axis of the progress bar will be center-aligned to the parent.
 * @return a progress bar.
 */
private static JProgressBar createProgressBar(final JComponent parent) {
  final JProgressBar progressBar = new JProgressBar();
  progressBar.setSize(260, 20);
  parent.addComponentListener(new ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      progressBar.setLocation(
        parent.getWidth() / 2 - progressBar.getWidth() / 2,
        parent.getHeight() - progressBar.getHeight() - 20);
    }
  });
  progressBar.setStringPainted(true);
  progressBar.setIndeterminate(true);
  progressBar.setVisible(false);
  return progressBar;
}
 
Example 2
/**
 * Creates a progress bar.
 * 
 * @param parent progress bar's parent. The horizontal axis of the progress bar will be center-aligned to the parent.
 * @return a progress bar.
 */
private static JProgressBar createProgressBar(final JComponent parent) {
  final JProgressBar progressBar = new JProgressBar();
  progressBar.setSize(260, 20);
  parent.addComponentListener(new ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      progressBar.setLocation(
        parent.getWidth() / 2 - progressBar.getWidth() / 2,
        parent.getHeight() - progressBar.getHeight() - 20);
    }
  });
  progressBar.setStringPainted(true);
  progressBar.setIndeterminate(true);
  progressBar.setVisible(false);
  return progressBar;
}
 
Example 3
@Override
public void addNotify() {
    super.addNotify();
    scene.addSceneListener(this);
    JComponent viewComponent = scene.getView();
    if (viewComponent == null) {
        viewComponent = scene.createView();
    }
    viewComponent.addComponentListener(this);
    repaint();
}
 
Example 4
@Override
public void addNotify() {
    super.addNotify();
    scene.addSceneListener(this);
    JComponent viewComponent = scene.getView();
    if (viewComponent == null) {
        viewComponent = scene.createView();
    }
    viewComponent.addComponentListener(this);
    repaint();
}
 
Example 5
Source Project: pumpernickel   File: MultiThumbSliderUI.java    License: MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent slider) {
	slider.addMouseListener(this);
	slider.addMouseMotionListener(this);
	slider.addFocusListener(focusListener);
	slider.addKeyListener(keyListener);
	slider.addComponentListener(compListener);
	slider.addPropertyChangeListener(propertyListener);
	slider.addPropertyChangeListener(THUMB_SHAPE_PROPERTY,
			thumbShapeListener);
	calculateGeometry();
}
 
Example 6
Source Project: pumpernickel   File: ThumbnailLabelUI.java    License: MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);
	c.addComponentListener(repaintComponentListener);
	JLabel label = (JLabel) c;
	label.setHorizontalTextPosition(SwingConstants.CENTER);
	label.setIconTextGap(3);
}
 
Example 7
Source Project: pumpernickel   File: BoxTabbedPaneUI.java    License: MIT License 5 votes vote down vote up
private void installExtraComponents(Container container,
		List<JComponent> components, boolean forceReinstall) {
	if (components == null)
		components = new ArrayList<>();
	Component[] oldComponents = container.getComponents();
	if (!Arrays.asList(oldComponents).equals(components)) {
		forceReinstall = true;
	}

	if (forceReinstall) {
		container.removeAll();
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 100;
		c.weightx = 1;
		c.weighty = 1;
		c.fill = GridBagConstraints.BOTH;
		for (JComponent jc : components) {
			container.add(jc, c);
			if (tabs.getTabPlacement() == SwingConstants.LEFT) {
				c.gridy--;
			} else if (tabs.getTabPlacement() == SwingConstants.RIGHT) {
				c.gridy++;
			} else {
				c.gridx++;
			}
			jc.removeComponentListener(extraComponentListener);
			jc.addComponentListener(extraComponentListener);

			for (Component oldComponent : oldComponents) {
				if (components.contains(oldComponent)) {
					oldComponent
							.removeComponentListener(extraComponentListener);
				}
			}
		}
		container.revalidate();
	}
	refreshExtraContainerVisibility();
}
 
Example 8
@Override
public void installUI(JComponent slider) {
	slider.addMouseListener(this);
	slider.addMouseMotionListener(this);
	slider.addFocusListener(focusListener);
	slider.addKeyListener(keyListener);
	slider.addComponentListener(compListener);
	slider.addPropertyChangeListener(propertyListener);
	slider.addPropertyChangeListener(THUMB_SHAPE_PROPERTY, thumbShapeListener);
	calculateGeometry();
}
 
Example 9
void addComponentListenerTo(JComponent comp) {
	comp.addComponentListener(compListener);
}