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

The following examples show how to use javax.swing.JComponent#addHierarchyListener() . 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: PackagesView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private void initListeners(final JComponent view) {
    view.addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                if (view.isShowing()) {
                    view.removeHierarchyListener(this);
                    loadPackages(view);
                }
            }
        }
    });
    controller.addListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            refreshState(view);
        }
    });
}
 
Example 2
Source File: ProviderToggleAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void installVisibilityTracker( final ComponentProviderAdapter provider ) {
    JComponent component = provider.getComponent();
    component.addHierarchyListener( new HierarchyListener() {
        
        public void hierarchyChanged( HierarchyEvent e ) {
            long changeFlags = e.getChangeFlags();
            if ( HierarchyEvent.SHOWING_CHANGED ==
                (changeFlags & HierarchyEvent.SHOWING_CHANGED) ) {
                setSelected( provider.isVisible() );
            }
        }
    } );
}
 
Example 3
Source File: Oculus.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static void showDialog(String title, String message, int style) {
   JTextArea area = new JTextArea(message);
   area.setBackground(UIManager.getColor("OptionPane.background"));
   area.setEditable(false);
   JComponent content = area;

   // If the message is too long then wrap it in
   // a scrollable text area and make the font
   // fixed width.
   if (message.length() >= 128) {
      area.setFont(new Font("monospaced", Font.PLAIN, 12));

      JScrollPane jp = new JScrollPane(area);
      jp.getViewport().add(area);

      //area.setColumns(80);
      area.setLineWrap(true);

      jp.setPreferredSize(new Dimension(800,600));
      content = jp;
   }

   // Make the dialog resizable:
   // https://blogs.oracle.com/scblog/entry/tip_making_joptionpane_dialog_resizable
   final JComponent pane = content;
   pane.addHierarchyListener(new HierarchyListener() {
      public void hierarchyChanged(HierarchyEvent e) {
         Window window = SwingUtilities.getWindowAncestor(pane);
         if (window instanceof Dialog) {
            Dialog dialog = (Dialog)window;
            if (!dialog.isResizable()) {
               dialog.setResizable(true);
            }
         }
      }
   });

   JOptionPane.showMessageDialog(MAIN, pane, title, style);
}
 
Example 4
Source File: Oculus.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static int showOKCancelDialog(String title, String message) {
   JTextArea area = new JTextArea(message);
   area.setBackground(UIManager.getColor("OptionPane.background"));
   area.setEditable(false);
   JComponent content = area;

   // If the message is too long then wrap it in
   // a scrollable text area and make the font
   // fixed width.
   if (message.length() >= 128) {
      area.setFont(new Font("monospaced", Font.PLAIN, 12));

      JScrollPane jp = new JScrollPane(area);
      jp.getViewport().add(area);

      //area.setColumns(80);
      area.setLineWrap(true);

      jp.setPreferredSize(new Dimension(800,600));
      content = jp;
   }

   // Make the dialog resizable:
   // https://blogs.oracle.com/scblog/entry/tip_making_joptionpane_dialog_resizable
   final JComponent pane = content;
   pane.addHierarchyListener(new HierarchyListener() {
      public void hierarchyChanged(HierarchyEvent e) {
         Window window = SwingUtilities.getWindowAncestor(pane);
         if (window instanceof Dialog) {
            Dialog dialog = (Dialog)window;
            if (!dialog.isResizable()) {
               dialog.setResizable(true);
            }
         }
      }
   });
   Object[] options = {"Cancel", "OK"};
   return JOptionPane.showOptionDialog(MAIN, pane, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
}
 
Example 5
Source File: RootPaneListener.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * This adds this listener to the argument <code>JComponent</code>.
 * 
 * @param jc
 *            the component added to this hierarchy tree.
 */
public void add(JComponent jc) {
	jc.addHierarchyListener(hierarchyListener);
	Object value = jc.getRootPane();
	if (value == null)
		value = NULL_VALUE;
	rootPanes.put(jc, value);
}
 
Example 6
Source File: BasicAudioPlayerUI.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);

	getFields(c).install();
	c.addPropertyChangeListener(AudioPlayerComponent.SOURCE_KEY,
			updateSourceListener);
	c.addHierarchyListener(hierarchyListener);
}
 
Example 7
Source File: SwingSet3.java    From littleluck with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent e) {
    String propertyName = e.getPropertyName();
    if (propertyName.equals("demoComponent")) {
        Demo demo = (Demo)e.getSource();
        JComponent demoComponent = (JComponent)e.getNewValue();
        if (demoComponent != null) {
            demoComponent.putClientProperty("swingset3.demo", demo);
            demoComponent.addHierarchyListener(new DemoVisibilityListener());
            registerPopups(demoComponent);
        }
    } 
}
 
Example 8
Source File: SwingSet3.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent e) {
    String propertyName = e.getPropertyName();
    if (propertyName.equals("demoComponent")) {
        Demo demo = (Demo)e.getSource();
        JComponent demoComponent = (JComponent)e.getNewValue();
        if (demoComponent != null) {
            demoComponent.putClientProperty("swingset3.demo", demo);
            demoComponent.addHierarchyListener(new DemoVisibilityListener());
            registerPopups(demoComponent);
        }
    } 
}