Tabnine Logo
AWTEvent
Code IndexAdd Tabnine to your IDE (free)

How to use
AWTEvent
in
java.awt

Best Java code snippets using java.awt.AWTEvent (Showing top 20 results out of 918)

Refine searchRefine arrow

  • Window
  • JFrame
  • Container
  • Component
  • JComponent
origin: magefree/mage

private void handleEvent(AWTEvent event) {
  MagePane frame = activeFrame;
  // support multiple mage panes
  Object source = event.getSource();
  if (source instanceof Component) {
    Component component = (Component) source;
    while (component != null) {
      if (component instanceof MagePane) {
        frame = (MagePane) component;
        break;
      }
      component = component.getParent();
    }
  }
  if (frame != null) {
    frame.handleEvent(event);
  }
}
origin: stackoverflow.com

JFrame f = new JFrame("Listeners");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JCheckBox b = new JCheckBox("JCheckBox");
b.addActionListener(new ActionListener() {
    System.out.println(e.getID() == ActionEvent.ACTION_PERFORMED
      ? "ACTION_PERFORMED" : e.getID());
p.add(b);
f.add(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
origin: stackoverflow.com

long eventMask = AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK;
 Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
   public void eventDispatched(AWTEvent e) {
     System.out.println(e.paramString()+"-"+e.getSource());
   }
 }, eventMask);
origin: joel-costigliola/assertj-swing

/**
 * Indicates whether the id of the given event is equal to {@code WindowEvent.COMPONENT_SHOWN} and the source of the
 * event is a {@code Window}.
 * 
 * @param e the given event.
 * @return {@code true} if the id of the given event is equal to {@code COMPONENT_SHOWN} and the source of the event
 *         is a {@code Window}; {@code false} otherwise.
 */
public static boolean wasWindowShown(@Nonnull AWTEvent e) {
 return e.getID() == COMPONENT_SHOWN && e.getSource() instanceof Window;
}
origin: stackoverflow.com

JButton b1 = new JButton("B1");
JButton b2 = new JButton("B2");
tf2.setEnabled(false);
focusList = new Component[]{tf1, b1, tf2, b2, tf3};
JPanel panel = new JPanel(new GridLayout(5, 1));
panel.add(tf1);
panel.add(b1);
panel.add(tf2);
panel.add(b2);
panel.add(tf3);
frame = new JFrame();
frame.setFocusTraversalPolicy(new MyFocusTraversalPolicy());
frame.add(panel);
frame.pack();
frame.setLocation(150, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
    if (ke.getID() == KeyEvent.KEY_PRESSED) {
      if (ke.getKeyCode() == KeyEvent.VK_TAB) {
        Component comp = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        if (comp.isEnabled() == false) {
          if (ke.isShiftDown()) {
            KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent();
origin: stackoverflow.com

header.getActionMap().put("toggleSortOrder2", new AbstractAction() {
    e.setSource(table);
    table.getActionMap().get("focusHeader").actionPerformed(e);
    if (selectedColumn != null) {
      int i = header.getColumnModel().getColumnIndex(selectedColumn);
    header.repaint();
InputMap im = header.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), "toggleSortOrder2");
header.addMouseListener(new MouseAdapter() {
header.setToolTipText("Sorting by F8");
JPanel p = new JPanel(new BorderLayout());
p.add(new JScrollPane(table));
return p;
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.getContentPane().add(new SelectedColumnTest().makeUI());
f.setSize(320, 240);
f.setLocationRelativeTo(null);
f.setVisible(true);
origin: stackoverflow.com

 ((JSlider)getComponent(slider)).setValue(value);
public void doLayout()
 Insets i=getInsets();
 int x=i.left, y=i.top, width=getWidth()-x-i.right, height=getHeight()-y-i.bottom;
 for(int ix=0, n=getComponentCount(); ix<n; ix++)
  getComponent(ix).setBounds(x, y, width, height);
  if(e.getID()==MouseEvent.MOUSE_PRESSED) active=sl;
  else if(e.getID()==MouseEvent.MOUSE_RELEASED) active=null;
  if(e.getID()==MouseEvent.MOUSE_CLICKED)
  e.setSource(this);
  super.processMouseEvent(e);
 protected void processMouseMotionEvent(MouseEvent e)
  if(e.getID()==MouseEvent.MOUSE_MOVED)
   toAllSliders(e);
  else
  e.setSource(this);
  super.processMouseMotionEvent(e);
 repaint();
 slider.setFocusable(false);
origin: stackoverflow.com

setLayout(new BorderLayout());
mouseWheelListener = createMouseWheelListener();
tipArea = new JTextArea(rows, columns);
    JComponent component = getComponent();
    if (component != null) {
      tipArea.dispatchEvent(new MouseWheelEvent(tipArea, e.getID(),
          e.getWhen(), e.getModifiers(), 0, 0, e.getClickCount(),
          e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(),
JComponent component = getComponent();
if (component != null) {
  component.addMouseWheelListener(mouseWheelListener);
JComponent component = getComponent();
if (component != null) {
  component.removeMouseWheelListener(mouseWheelListener);
return getComponent(0).getPreferredSize();
      e.printStackTrace();
    f.setVisible(true);
origin: stackoverflow.com

 p.add(new JLayer<JTabbedPane>(tabbedPane, new CloseableTabbedPaneLayerUI()));
 p.add(new JButton(new AbstractAction("add tab") {
  @Override public void actionPerformed(ActionEvent e) {
   tabbedPane.addTab("test", new JPanel());
 JFrame f = new JFrame();
 f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 f.getContentPane().add(new CloseableTabbedPaneTest().makeUI());
 f.setSize(320, 240);
 f.setLocationRelativeTo(null);
 f.setVisible(true);
public CloseableTabbedPaneLayerUI() {
 super();
 button.setBorder(BorderFactory.createEmptyBorder());
 button.setFocusPainted(false);
 button.setBorderPainted(false);
 if (e.getID() == MouseEvent.MOUSE_CLICKED) {
  pt.setLocation(e.getPoint());
  JTabbedPane tabbedPane = (JTabbedPane) l.getView();
  l.getView().repaint();
  tabbedPane.repaint(tabbedPane.getBoundsAt(index));
 } else {
  tabbedPane.repaint();
origin: stackoverflow.com

if (event instanceof FocusEvent) {
  FocusEvent focusEvent = (FocusEvent) event;
  if (focusEvent.getID() == FocusEvent.FOCUS_LOST) {
    Component focusTo = focusEvent.getOppositeComponent();
    Component focusFrom = focusEvent.getComponent();
    if (focusTo == null || !focusTo.getParent().equals(table)) {
  if (mouseEvent.getID() == MouseEvent.MOUSE_CLICKED) {
    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    JTable table = getTableFrom(focusOwner);
    System.out.println("focusOwner = " + focusOwner);
    if ((table != null && mouseEvent.getComponent() != table) && (focusOwner != null && !focusOwner.getParent().equals(table))) {
      stopCellEditing(table);
      clearSelection(table);
if (component instanceof JTable) {
  table = (JTable) component;
} else if (component != null && component.getParent() instanceof JTable) {
  table = (JTable) component.getParent();
origin: stackoverflow.com

  enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
  g.fillRect(0, 0, getWidth(), getHeight());
  if (e.getID() == MouseEvent.MOUSE_PRESSED && e.getButton() == MouseEvent.BUTTON1) {
      e.consume();
  } else if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
      e.consume();
  } else if (e.getID() == MouseEvent.MOUSE_RELEASED && e.getButton() == MouseEvent.BUTTON1) {
    repaint();
JFrame frame = new JFrame("Panel Drag Example");
frame.getContentPane().add(new DragPanel());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(640, 480);
frame.setVisible(true);
origin: stackoverflow.com

box.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 20));
box.add(makeTitledPanel("Default", slider0));
box.add(Box.createVerticalStrut(20));
box.add(makeTitledPanel(
  "Override TrackListener#shouldScroll(...): false",  slider1));
box.add(Box.createVerticalStrut(20));
p.setBorder(BorderFactory.createTitledBorder(title));
p.add(c, BorderLayout.NORTH);
return p;
 JFrame f = new JFrame();
 f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 f.getContentPane().add(new MainPanel().makeUI());
 f.setSize(320, 240);
 f.setLocationRelativeTo(null);
 f.setVisible(true);
});
if (e.getID() == MouseEvent.MOUSE_PRESSED && SwingUtilities.isLeftMouseButton(e)) {
 JSlider slider = (JSlider) e.getComponent();
 MouseEvent me = new MouseEvent(
  slider,
  e.getID(), e.getWhen(),
 slider.dispatchEvent(me);
origin: stackoverflow.com

private JFrame frame = new JFrame();
  Toolkit.getDefaultToolkit().addAWTEventListener(this, Long.MAX_VALUE);
  panel = new JPanel();
  panel.setBackground(Color.red);
  panel.setBorder(new LineBorder(Color.black, 1));
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(panel);
  frame.setPreferredSize(new Dimension(300, 300));
  frame.pack();
  frame.setVisible(true);
  System.out.println(event);
  if (event instanceof MouseEvent) {
    if (event.getID() == MouseEvent.MOUSE_PRESSED) {
      Timer timer = new Timer(500, new ActionListener() {
        @Override
  frame.remove(panel);
  panel = new JPanel();
  panel.setBorder(new LineBorder(Color.black, 1));
  frame.add(panel);
  frame.validate();
  frame.repaint();
  frame.setPreferredSize(new Dimension((int) Math.random() * 50 + 300, (int) Math.random() * 50 + 300));
  frame.pack();
  System.err.println("stuff done");
origin: stackoverflow.com

typingArea.addKeyListener(this);
scrollPane.setPreferredSize(new Dimension(375, 125));
add(typingArea, BorderLayout.PAGE_START);
add(scrollPane, BorderLayout.CENTER);
add(button, BorderLayout.PAGE_END);
displayArea.setText("");
typingArea.setText("");
typingArea.requestFocusInWindow();
int id = e.getID();
if (id == KeyEvent.KEY_TYPED) {
 char c = e.getKeyChar();
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("KeyEventDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent newContentPane = new KeyEventTest();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
origin: stackoverflow.com

content.add(new JLabel("Creature"));
JButton badger = new JButton("Badger");
badger.setName("badger");
JButton ferret = new JButton("Ferret");
ferret.setName("ferret");
JButton stoat = new JButton("Stoat");
stoat.setName("stoat");
content.add(badger);
content.add(ferret);
JButton close = new JButton(frame.getRootPane().getActionMap().get(ACTION_CLOSE));
frame.setSize(200, 150);
frame.pack();
frame.getRootPane().getActionMap().put(ACTION_CLOSE, close);
    if (event instanceof MouseEvent) {
      MouseEvent m = (MouseEvent) event;
      if (m.getID() == MouseEvent.MOUSE_CLICKED) {
        System.out.println(m.toString());
origin: stackoverflow.com

JTextArea textArea = new JTextArea("This is a working text area\n\nI LOVE SWING", 4, 0);
textArea.setCursor(Cursor.getDefaultCursor());
mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
mainPanel.add(new JLabel("A Normal Label"), BorderLayout.NORTH);
mainPanel.add(textArea, BorderLayout.CENTER);
mainPanel.add(new JButton("Hello World!"), BorderLayout.SOUTH);
        BufferedImage im = new BufferedImage(this.getWidth(), this.getHeight(),
            BufferedImage.TYPE_3BYTE_BGR);
        f.paint(f.getGraphics());
      MouseEvent evt = new MouseEvent(
          me.getComponent(),
          me.getID(),
          me.getWhen(),
          me.getModifiers(),
          f.getWidth() - me.getX() + f.getInsets().right - f.getInsets().left,
          f.getHeight() - me.getY() + f.getInsets().top - f.getInsets().bottom,
          me.getClickCount(),
          false,
Toolkit.getDefaultToolkit().getSystemEventQueue().push(queue);
origin: stackoverflow.com

realListeners = scrollPane.getMouseWheelListeners();
  scrollPane.removeMouseWheelListener(mwl);
scrollPane.addMouseWheelListener(this);
  e.getID(),
  e.getWhen(),
  e.getModifiers(),
    JTextArea textArea = new JTextArea(5, 20);
    JScrollPane scrollPane = new JScrollPane( textArea );
    scrollPane.setMinimumSize( scrollPane.getPreferredSize() );
    new MouseWheelToParent(scrollPane);
    panel.add(scrollPane, gbc);
JFrame frame = new JFrame("TextAreaSSCCE");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add( new JScrollPane( panel ) );
frame.setSize(400, 400);
frame.setLocationByPlatform( true );
frame.setVisible( true );
origin: stackoverflow.com

  table.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
      printDebugData(table);
  @Override
  public boolean dispatchKeyEvent(KeyEvent e) {
   if(e.getID() == KeyEvent.KEY_PRESSED)
add(scrollPane);
JFrame frame = new JFrame("SimpleTableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
origin: stackoverflow.com

popup.add(new JMenu("aAaa"));
JPanel contentPane = new JPanel();
contentPane.add(popup);
JButton b = new JButton();
b.setAction(new AbstractAction("Button")
contentPane.add(b);
contentPane.addMouseListener(new MouseAdapter() {
  @Override
  public void mousePressed(MouseEvent e)
    if(me.getID() == MouseEvent.MOUSE_PRESSED)
JFrame f = new JFrame();
f.setContentPane(contentPane);
f.setSize(400, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
origin: stackoverflow.com

  menu.add(new MyMenuItem("Bananas"));
  JFrame frame = new JFrame("Testing");
  frame.setJMenuBar(mb);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(new TestPane());
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
if (evt.getID() == MouseEvent.MOUSE_RELEASED && contains(evt.getPoint())) {
  doClick();
  setArmed(true);
java.awtAWTEvent

Javadoc

The root event class for all AWT events. This class and its subclasses supercede the original java.awt.Event class. Subclasses of this root AWTEvent class defined outside of the java.awt.event package should define event ID values greater than the value defined by RESERVED_ID_MAX.

The event masks defined in this class are needed by Component subclasses which are using Component.enableEvents() to select for event types not selected by registered listeners. If a listener is registered on a component, the appropriate event mask is already set internally by the component.

The masks are also used to specify to which types of events an AWTEventListener should listen. The masks are bitwise-ORed together and passed to Toolkit.addAWTEventListener.

Most used methods

  • getSource
  • getID
    Returns the event type.
  • paramString
    Returns a string representing the state of this Event. This method is intended to be used only for d
  • setSource
  • toString
    Returns a String representation of this object.

Popular in Java

  • Making http post requests using okhttp
  • getSharedPreferences (Context)
  • setRequestProperty (URLConnection)
  • runOnUiThread (Activity)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now