本文整理匯總了Java中java.awt.event.ComponentListener類的典型用法代碼示例。如果您正苦於以下問題:Java ComponentListener類的具體用法?Java ComponentListener怎麽用?Java ComponentListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ComponentListener類屬於java.awt.event包,在下文中一共展示了ComponentListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setMinimumSizeManager
import java.awt.event.ComponentListener; //導入依賴的package包/類
/**
* Installs/resets a ComponentListener to resize the
* given window to minWidth/Height if needed.
*
* @param window
* @param minWidth
* @param minHeight
*/
public static void setMinimumSizeManager(Window window, int minWidth,
int minHeight) {
ComponentListener[] listeners = window.getComponentListeners();
ComponentListener listener = null;
for (ComponentListener l : listeners) {
if (l instanceof MinSizeComponentListener) {
listener = l;
break;
}
}
if (listener == null) {
window.addComponentListener(new MinSizeComponentListener(
window, minWidth, minHeight));
} else {
((MinSizeComponentListener) listener).resetSizes(minWidth,
minHeight);
}
}
示例2: createSelfManagedScrollPane
import java.awt.event.ComponentListener; //導入依賴的package包/類
/**
* Creates and returns a scroll panel which wraps the specified view component.<br>
* The returned scroll panel disables vertical scroll bar, and only displays the horizontal scroll bar when the view does not fit
* into the size of the view port. When the view fits into the view port, the scroll pane will not claim the space of the scroll bar.
*
* @param view view to wrap in the scroll pane
* @param parentToRevalidate parent to revalidate when the scroll pane decides to change its size
*
* @return the created self managed scroll pane
*/
public static JScrollPane createSelfManagedScrollPane( final Component view, final JComponent parentToRevalidate ) {
final JScrollPane scrollPane = new JScrollPane( view );
scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_NEVER );
scrollPane.getHorizontalScrollBar().setPreferredSize( new Dimension( 0, 12 ) ); // Only want to restrict the height, width doesn't matter (it takes up whole width)
scrollPane.getHorizontalScrollBar().setUnitIncrement( 10 );
final ComponentListener scrollPaneComponentListener = new ComponentAdapter() {
@Override
public void componentResized( final ComponentEvent event ) {
scrollPane.setHorizontalScrollBarPolicy( view.getWidth() < scrollPane.getWidth() ? JScrollPane.HORIZONTAL_SCROLLBAR_NEVER : JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
scrollPane.setPreferredSize( null );
scrollPane.setPreferredSize( new Dimension( 10, scrollPane.getPreferredSize().height ) );
parentToRevalidate.revalidate();
}
};
scrollPane.addComponentListener( scrollPaneComponentListener );
return scrollPane;
}
示例3: removeAllListeners
import java.awt.event.ComponentListener; //導入依賴的package包/類
/**
* Removes all listeners associated with the given Component. This is useful when removing to to make sure
* it does not stick around.
*/
public static void removeAllListeners(Component com) {
for (FocusListener fl : com.getFocusListeners()) {
com.removeFocusListener(fl);
}
for (MouseListener ml : com.getMouseListeners()) {
com.removeMouseListener(ml);
}
for (MouseMotionListener mml : com.getMouseMotionListeners()) {
com.removeMouseMotionListener(mml);
}
for (KeyListener kl : com.getKeyListeners()) {
com.removeKeyListener(kl);
}
for (ComponentListener cl : com.getComponentListeners()) {
com.removeComponentListener(cl);
}
}
示例4: setMinimumSizeManager
import java.awt.event.ComponentListener; //導入依賴的package包/類
/**
* Installs/resets a ComponentListener to resize the
* given window to minWidth/Height if needed.
*
* @param window
* @param minWidth
* @param minHeight
*/
public static void setMinimumSizeManager(Window window, int minWidth,
int minHeight) {
ComponentListener[] listeners = window.getComponentListeners();
ComponentListener listener = null;
for (ComponentListener l : listeners) {
if (l instanceof MinSizeComponentListener) {
listener = l;
break;
}
}
if (listener == null) {
window.addComponentListener(new MinSizeComponentListener(
window, minWidth, minHeight));
} else {
((MinSizeComponentListener) listener).resetSizes(minWidth,
minHeight);
}
}
示例5: addView
import java.awt.event.ComponentListener; //導入依賴的package包/類
public DockingWindow addView(int order, Configurable obj) {
Component component = (Component) obj.getData().getProperty(TabProperty.COMPONENT);
View view = new View(
(String) obj.getData().getProperty(TabProperty.TITLE),
(Icon) obj.getData().getProperty(TabProperty.ICON),
component
);
if (component instanceof ComponentListener) {
view.addComponentListener((ComponentListener) component);
}
if (order == 1 && obj instanceof DockingWindowListener) {
DockingWindowListener dockingWindowListener = (DockingWindowListener) obj;
view.addListener(dockingWindowListener);
if (firstTabWindow.getChildWindowCount() == 0) {
dockingWindowListener.windowShown(view);
}
}
return addView(order, view);
}
示例6: firePaletteEvent
import java.awt.event.ComponentListener; //導入依賴的package包/類
/**
* Fire a component event to the Layer component listeners, with the palette
* as the component, letting them know if it's visible or not.
*/
public void firePaletteEvent(ComponentEvent event) {
if (localHackList == null) {
return;
}
palette = (Container) event.getSource();
int eventType = event.getID();
for (ComponentListener listener : localHackList) {
if (eventType == ComponentEvent.COMPONENT_HIDDEN) {
listener.componentHidden(event);
} else if (eventType == ComponentEvent.COMPONENT_SHOWN) {
listener.componentShown(event);
}
}
if (eventType == ComponentEvent.COMPONENT_HIDDEN) {
palette = null;
}
}
示例7: getPaletteWindow
import java.awt.event.ComponentListener; //導入依賴的package包/類
/**
* Get a layer's associated palette as a top-level window
*
* @param gui the Component to place in the window
* @param cl the listener to associate with the palette
* @return the frame that the palette is in
*/
public static JFrame getPaletteWindow(Component gui, String windowName,
ComponentListener cl) {
JScrollPane scrollPane = new JScrollPane(gui, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
scrollPane.setAlignmentY(Component.TOP_ALIGNMENT);
// create the palette internal window
JFrame paletteWindow = new JFrame(windowName);
paletteWindow.addComponentListener(cl);
paletteWindow.getContentPane().add(scrollPane);
//layout all the components
paletteWindow.pack();
return paletteWindow;
}
示例8: getNoScrollPaletteWindow
import java.awt.event.ComponentListener; //導入依賴的package包/類
/**
* Get a layer's associated palette as a top-level window
*
* @param gui the Component to place in the window
* @param cl the listener to associate with the palette
* @return the frame that the palette is in
*/
public static JFrame getNoScrollPaletteWindow(Component gui,
String windowName,
ComponentListener cl) {
JPanel pane = new JPanel();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
pane.setAlignmentX(Component.CENTER_ALIGNMENT);
pane.setAlignmentY(Component.BOTTOM_ALIGNMENT);
pane.add(gui);
JFrame paletteWindow = new JFrame(windowName);
paletteWindow.addComponentListener(cl);
paletteWindow.getContentPane().add(pane);
paletteWindow.pack();
return paletteWindow;
}
示例9: setContent
import java.awt.event.ComponentListener; //導入依賴的package包/類
/**
* Sets the content in the JInternalFrame/JDialog.
*/
public void setContent(Component comp) {
if (content instanceof ComponentListener) {
removeComponentListener((ComponentListener) content);
}
content = comp;
if (display != null) {
display.setContent(comp);
}
if (content instanceof ComponentListener) {
addComponentListener((ComponentListener) content);
}
}
示例10: getListeners
import java.awt.event.ComponentListener; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
if (ComponentListener.class.isAssignableFrom(listenerType)) {
return (T[]) getComponentListeners();
} else if (FocusListener.class.isAssignableFrom(listenerType)) {
return (T[]) getFocusListeners();
} else if (HierarchyBoundsListener.class.isAssignableFrom(listenerType)) {
return (T[]) getHierarchyBoundsListeners();
} else if (HierarchyListener.class.isAssignableFrom(listenerType)) {
return (T[]) getHierarchyListeners();
} else if (InputMethodListener.class.isAssignableFrom(listenerType)) {
return (T[]) getInputMethodListeners();
} else if (KeyListener.class.isAssignableFrom(listenerType)) {
return (T[]) getKeyListeners();
} else if (MouseWheelListener.class.isAssignableFrom(listenerType)) {
return (T[]) getMouseWheelListeners();
} else if (MouseMotionListener.class.isAssignableFrom(listenerType)) {
return (T[]) getMouseMotionListeners();
} else if (MouseListener.class.isAssignableFrom(listenerType)) {
return (T[]) getMouseListeners();
} else if (PropertyChangeListener.class.isAssignableFrom(listenerType)) {
return (T[]) getPropertyChangeListeners();
}
return (T[]) Array.newInstance(listenerType, 0);
}
示例11: processComponentEventImpl
import java.awt.event.ComponentListener; //導入依賴的package包/類
private void processComponentEventImpl(ComponentEvent e, Collection<ComponentListener> c) {
for (ComponentListener listener : c) {
switch (e.getID()) {
case ComponentEvent.COMPONENT_HIDDEN:
listener.componentHidden(e);
break;
case ComponentEvent.COMPONENT_MOVED:
listener.componentMoved(e);
break;
case ComponentEvent.COMPONENT_RESIZED:
listener.componentResized(e);
break;
case ComponentEvent.COMPONENT_SHOWN:
listener.componentShown(e);
break;
}
}
}
示例12: hideMe
import java.awt.event.ComponentListener; //導入依賴的package包/類
private void hideMe() {
final JComponent parent = (JComponent) textfield.getParent();
final Rectangle bounds = textfield.getBounds();
textfield.removeFocusListener(textFieldListener);
textfield.removeKeyListener((KeyListener) textFieldListener);
textfield.removeMouseListener((MouseListener) textFieldListener);
mFocusListener
.removeComponentListener((ComponentListener) textFieldListener);
// workaround for java bug
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7075600, see
// FreeMindStarter
parent.remove(textfield);
parent.revalidate();
parent.repaint(bounds);
textFieldListener = null;
}
示例13: showPopupPanel
import java.awt.event.ComponentListener; //導入依賴的package包/類
private void showPopupPanel() {
if (mPopup == null)
mPopup = new ComponentUtils.ModalPopup(this);
PopupPanel panel = this.getPanel().orElse(null);
if (panel == null)
return;
mPopup.removeAll();
panel.onShow();
for (ComponentListener cl : panel.getComponentListeners())
panel.removeComponentListener(cl);
panel.addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(ComponentEvent e) {
mPopup.close();
}
});
mPopup.add(panel);
mPopup.showPopup();
}
示例14: getComponentListener
import java.awt.event.ComponentListener; //導入依賴的package包/類
/** Create a component listener to handle size changes if the table model
* is large-model */
private ComponentListener getComponentListener() {
if (componentListener == null) {
componentListener = new SizeManager();
}
return componentListener;
}
示例15: removeNotify
import java.awt.event.ComponentListener; //導入依賴的package包/類
@Override
public void removeNotify() {
super.removeNotify();
for (ComponentListener l : getComponentListeners()) {
super.removeComponentListener(l);
}
}