Event « JFrame « Java Swing Q&A





1. How can a JComponent notified about the closed event of it's parent J(Internal)Frame?    stackoverflow.com

I want to write a component that monitors other activities, but it's listeners are to be removed when the component's window is closed. I don't want to write this removal code many ...

2. Tracking OS-level window events in Java    stackoverflow.com

I have a requirement to be able to track how much a user interacts with the different applications running on their machine. What seemed logical to me was to keep a ...

3. Window events for JFrames that are hidden/shown via setVisible?    stackoverflow.com

Which sort of listener do I have to add to a JFrame to detect when it is being hidden/shown via setVisible? I tried using a WindowListener and the windowOpened and ...

4. How to use something other than the DefaultClosingOperation when closing a JFrame window?    stackoverflow.com

I am working on a chat client using a socket, and I want a certain code to be executed before the window closes when the user clicks on "X" (like closing ...

5. How can I capture all mouse events in a JFrame/Swing?    stackoverflow.com

I have a JFrame that has a large number of changing child components. (Many layers) Is there any way to add a listener for all mouse events? Something like KeyEventDispatcher?

6. MouseListener on JFrame    stackoverflow.com

I want to be notified of mouse events (specifically the mouse entered and exited events) on my JFrame. But when i add a mouselistener to it i get the events on ...

7. How could I implement new JFrame functionality    stackoverflow.com

I am trying to remove the drag bar across the top of the JFrame. I would like to keep the minimize maximize and close options that appear on this bar available. ...

8. close window event in java    stackoverflow.com

I added an window state listener as follow:

this.addWindowStateListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
          ...

9. Listen to JFrame resize events as the user drags their mouse?    stackoverflow.com

When a user clicks on the corner of a JFrame to resize and drags the mouse around, the JFrame redraws based on the current position of the mouse as the user ...





10. Window resize event?    stackoverflow.com

I'm writing a simple painting program using java, and I want some method to be called whenever the JFrame component is resized. But I can't find any method like windowResizedListener ...

11. how to obtain mouse click coordinates outside my window in Java    stackoverflow.com

I need to implement a class, using Swing, which can obtain the mouse coordinates when the user clicks anywhere on the screen. if I wanted to obtain the mouse coordinates inside ...

12. Error when creating JFrame from JFrame    stackoverflow.com

I have an application that is works fine and the JFrame for it is launched in the constructor of a GameInitializer class which takes in some config parameters. I have tried ...

13. Why do people run Java GUI's on the Event Queue    stackoverflow.com

In Java, to create and show a new JFrame, I simply do this:

public static void main(String[] args)
{
   new MyCustomFrameClass().setVisible(true);
}
However, I have seen many people doing it like this:
public ...

14. ActionListener isn't Implementing    stackoverflow.com

JFrameWithPanel is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener public class JFrameWithPanel extends JFrame implements ActionListener I Don't get this code. Book and Java site tells me this is ...

15. Updating text on JFrame depending on ActionListener    stackoverflow.com

This is a result of ActionListener. Depending on what he chooses in the Combo Box it returns a price. I just want it as a simple $39.99. Nothing more. I have ...

16. Event handling in modal windows (Java swing)    stackoverflow.com

I'm developing the Java Swing application. I'm quite new to Java, so got some questions. I have a modal window with some set of controls (text fields, buttons etc). I want ...





17. how can i increase/decrease size of window on click event?    stackoverflow.com

I am developing a simple swing app in which I have a main window with three buttons. When I click on the first button it opens new window of (200,200) dimension. ...

18. Java JFrame Resizing    stackoverflow.com

I know I can user componentResized to listen for when the user resizes a window. This isn't a very nice solution. If I do this and add a resize() method for ...

19. Prevent Enter Event from Bubbling to to Main Window    stackoverflow.com

I have a custom Swing component called NavigationLink which extends JLabel and implements a key event listener like so:

addKeyListener(new KeyAdapter() {
    public void keyReleased(KeyEvent e) {
   ...

20. JFrame to be displayed when the event occurs?    stackoverflow.com

I have a JFrame which pops up when the event occurs. I am having a functionality which when the event occurs the JFrame pops up and if we click on that ...

21. event when closing a Window, but without closing it    stackoverflow.com

I want to show a "Confirm Close" window when closing the main app window, but without making it disappear. Right now I am using a windowsListener, and more specifially the windowsClosing ...

22. Swing JFrame Responding to Native Window On Close Event    stackoverflow.com

I have a Swing application which consists of a single JFrame set to Always On Top. When running under Windows, I use the following code to open the the native default email ...

23. JFrame catch dispose event    stackoverflow.com


I have a Java project.
I have a JFrame with a handler attached to it liek so

frame.addWindowListener(new WindowAdapter() {

            public void ...

24. Event between X clicked/alt-F4 and windowsclosing() event    stackoverflow.com

I'm making a application with a main JFrame and some threads. I use a windowslistener on my frame to detect for the closing event. But sometimes when i close the application ...

25. Java Swing -- Asking for User Input (and creating a blocking thread) by popping up a JFrame    stackoverflow.com

My top-level container is MainFrame (JFrame). I want to be able to popup another JFrame with a JPanel that has two JTextFields from MainFrame. The thing is: I need to be able ...

26. Swing: How do I run a job from AWT thread, but after a window was layed out?    stackoverflow.com

My complete GUI runs inside the AWT thread, because I start the main window using SwingUtilities.invokeAndWait(...). Now I have a JDialog which has just to display a JLabel, which indicates that a ...

27. JFrame subclass and ActionListener interface implementation    stackoverflow.com

Why is extends JFrame implements ActionListener a bad design decision?

28. Is there a way to get keyboard events without JFrame?    stackoverflow.com

I want to get my program to unhide main window when user presses some shortcut. Is there a way to get the global key events, not only the ones which happened ...

29. Listen to mouse clicks on whole system (not on a JFrame etc.)    stackoverflow.com

I want to write a little code which react to a mouse click. But it seems the only way is to listen to clicks on Java components. A direct listener to ...

30. mouse event, not on Jframe    stackoverflow.com

i want to make my program to work after a mouse button was clicked, but not necessarily on a Jframe of some sort. for example, i want my program to start working after ...

31. Use a Java KeyListener on a background frame    stackoverflow.com

I have a content pane containing a JScrollPane wrapped around a non-editable JTextArea that I'm using to (right now) simply display info about what key is being pressed (was just trying ...

32. Null pointer exception when running actionPerformed, Java    stackoverflow.com

been looking in a dead gaze at my code and haven't got anywhere. the program compiles fine, but whenever Play.java runs 'actionPerformed' i get a Null Pointer Exception from the 'AWT-EventQueue-0' ...

33. JAVA click w/ mouse move w/ keyboard    stackoverflow.com

I'm kind of new in Java. I wanted to select an object inside the JFrame and move it with the keyboard arrow keys. I did the keyboard thing, whenever I pressed ...

34. close java frame using code    stackoverflow.com

Possible Duplicate:
How to close a java swing application from the code
I am developing a java GUI using JFrame. I want to close the GUI ...

35. Display one form and return text to another - Java    stackoverflow.com

I have an application in C# that I am converting to Java, specifically the C# version consists of a Windows Form (Main Form) that spawns a new form (Secondary Form) via ...

36. How can I pass mouse events on a translucent JWindow to the JFrame underneath?    stackoverflow.com

I am creating a Firefox style drag and drop tabbed pane based on this example. To implement the scaled tab images as you drag I am using a JWindow. ...

37. Detect all changes (made by the user) to the text in controls on the form    stackoverflow.com

I have a program with a Save() method that saves all data in spinners and textfields on the form. Is there a way to call "Save()" every time the user makes ...

38. Visual C++ main app accessing Swing window via JNI does not receive paint events    stackoverflow.com

We have a Visual C++ app that invokes a modal dialog, and from that modal dialog we create a JFrame-based Swing GUI via JNI calls. The C++ modal dialog ...

39. What Swing Event is Fired when JFrame is Moved to Front of Desktop    stackoverflow.com

Say I have a window over top of my JFrame. I then click the JFrame's button in the TaskBar. The JFrame is now on top of the other window. What event ...

40. KeyEvent not being generated by JFrame java?    stackoverflow.com

I have a java program with a JFrame and 3 JButtons in it. I have added a keylistener to jframe. When i run the program a jframe window is opened and ...

41. AWT Window Close Listener/Event    stackoverflow.com

I am sorry if this is a n00b question, but I have spent way too long for this once I create the Window listener, window event, and everything else, how do ...

42. java.lang.IllegalAccessException in a custom JFrame    stackoverflow.com

I have defined a few actions for my custom JFrame in Netbeans 7.0, which is being created in one method of FrameView object. all of them look like this:

@Action
public void actionMethodName(){
  ...

43. How to trigger an event when another window is closed?    stackoverflow.com

I have a button that open a new window to the user do some configurations. After the configuration window is closed, I want to reload the configurations in the window that ...

44. yes no confirm and window event    stackoverflow.com

I have following code snippet:

addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
     ...

45. Adding key and mouse listener    stackoverflow.com

I tried to add key and mouse listener to JFrame, it didn't work, also i find out that JFrame can't get focus. I have a function which loads the buffered image ...

46. Why won't this listener detect window close events?    stackoverflow.com

I'm trying to listen for events on a single Frame via WindowStateListener.

import java.awt.Frame;
import java.awt.Label;

import java.awt.event.WindowStateListener;
import java.awt.event.WindowEvent;

public class UserInterface implements WindowStateListener
{
    public static void main(final String[] arguments)
   ...

47. How to Subscribe to GUI Events in Other JFrames    stackoverflow.com

What is the best practice for subscribing to events from another JFrame? For example, I have a "settings" form, and when the user presses okay on the settings form, I ...

48. Canvas string click detection    stackoverflow.com

I'm working on a game and for the menus I'm using Canvases to draw the stuff for that menu. For options and buttons I'm using Graphics on the canvas to draw a ...

49. How to trap the Window minimizing event?    stackoverflow.com

I want to create a JFrame instance and on the click of its minimize button, I would like to hide it to the System Tray which is usually the taskbar of ...

50. Window Closing Event    coderanch.com

54. Traking JFrame window events    coderanch.com

I know how to write a window listener class. But I have always only written one for a single JFrame. Is it possoble to implement window listener in one class and invoke this class on multiple JFrames in one app? I am assuming that the answer to this question is yes, and if so, when I getSource() in the event windowEvent ...

55. Frame events    coderanch.com

58. JColorChooser white doesn't fire event    coderanch.com

61. Please tell me Window Resizing event    coderanch.com

62. Two JFrames in one app / event handling    coderanch.com

Hi Wolfgang, Have you tried without the \"s? Because, in Unix you can have a file called "runme.jar" (including the "). BTW there is some kind of a toolbox/api from sun for integrating help into your application. I am sure you can find it on google... P. [ September 02, 2004: Message edited by: Petr Blahos ]

63. SWT creating event? window does not redraw    coderanch.com

Hi all, i got a sash that should display two tables. in one of them i sometimes want to show a picture, depending on the connection state of a pda device. The table/picture are in a composite that itself is in the sash. On the click of a button i trigger a action that removes the table and creates the picture. ...

64. JFrame resize events    coderanch.com

65. Handling event In Jframe    coderanch.com

66. problem with Visibility of a frame after actionPerformed    coderanch.com

I am having a simple login window and in the actionPerformed of the Login Button I have to a lot of initialization for my application. But i want my Main Frame to be visible as soon as i click Login button This MainFrame is having a menu bar and different images Each of the tasks in actionPerformed are as separate threads. ...

67. JFrame event order (maximize)    coderanch.com

Hi, I have a problem regarding the order of JFrame events. I am using a frame, which can be closed. I want to achieve that on next reopening, it appears in the same place and in the same size as it was before it was closed. So I save its state, location and size. The problem is the next: if it ...

68. Popup window event    coderanch.com

HI all, I am creating a Java application in which i want to open a popup which displays some message.Currentl i am using JOptionPane.showMessageDialog(this,"msg"); method which shows dialog with OK button. But I dont understand how to fire an event in the OK button of this window. Is there any method by which i will be able to execure some code ...

69. capture events outside of JFrame    coderanch.com

70. event of Closeing JFrame    coderanch.com

71. actionPerformed in frame problem    coderanch.com

If the actionPerformed method is not inside the Viewer class, you will need to get a reference to a Viewer instance first, then call printClass on that instance. Alternatively, you can make the printClass method static and call it as Viewer.printClass(...). You can do this in this case since the printClass does not use any instance variables, only local variables and ...

74. JFrame + windowClosed event is not getting fired.    coderanch.com

logger.info("Showing the J3D Panel for optimized Container View"); try { JFrame frame = new JFrame(); frame.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { System.out.println("Window Closing........."); // Remove all component System.exit(0); } }); if (isOptimized()) // Show newly optimized container { boxOpt = new J3DContainerFrame(this); logger.info("The Container is optimized for boxes"); boxOpt.show3DProductBox(box_vectorMap, containerBox); frame.setLayout(new BorderLayout()); frame.getContentPane().add(boxOpt, BorderLayout.CENTER); } //frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.pack(); // frame.setLocation(120, ...

75. How to catch the close window event in a NetBeans Form ?    coderanch.com

All, I'm using NetBeans IDE to develop a java desktop application. This application makes use of threads. It starts with a JDialog and then the control goes to a Form which extends from FrameView. When I close this Form within the menu "File/Exit", everything works fine, the applications shuts down, as well all the threads. But when I close it using ...

76. Preferred method for passing toolbar events to JFrame    java-forums.org

Hi, I'm very new to Swing/AWT, but professional Java developer of over a decade. I am developing a simple Swing application, this is my first. I have looked at many of the examples for each component, but they all have one thing in common: They're simple and usually comprised of a single method that builds the entire UI. I understand that ...

77. JFrames and KeyEvents    java-forums.org

JFrame wnd = new JFrame(); // ... wnd.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent ke) { // Do nothing } @Override public void keyPressed(KeyEvent ke) { // Shifts the frames from right to left using the arrow keys if (ke.isAltDown()) { switch (ke.getKeyCode()) { case KeyEvent.VK_COMMA: globals.switchToFrame(globals.curFrame - 1); globals.editAreaNeedsRepainting = true; globals.frameInfoNeedsUpdating = true; globals.timelineNeedsRepainting = true; break; case KeyEvent.VK_PERIOD: ...

78. Applying action event on window closing?    java-forums.org

Hello everyone........ Please guide me that how can i apply an action event on window closing action?? Actually, in my swing application i have to store the information of current users that logged in into the database and this information is updated as user logged of, i have provided a button with logout actions but error occurred when user directly closes ...

79. Major help needed with drawing rectangles using JFrame and Mouse Events    java-forums.org

Good evening! So, I've been working on this program that draws rectangles using JFrame and implementing MouseListener and MouseMotionListener. You should be able to click and drag the mouse, drawing a rectangle, no matter where in the frame you start out. I have not had much luck getting it to work. The frame will display, but I am unable to draw ...

80. Question on Java Graphics, KeyBoard Events and JFrame    java-forums.org

This is my code so far (not including my main and JButton etc... classes. package Game; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.util.Scanner; import javax.swing.JFrame; public class Maze { BufferedImage img; JFrame frame; //Graphics g = img.getGraphics(); int x = 0; int y = 0; Graphics g; Maze(){ frame = new JFrame(); frame.setTitle("Maze"); frame.getContentPane(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E); ...

81. Question on Graphics/JFrame/KeyEvents    java-forums.org

package Game; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Starter extends JFrame implements ActionListener { Starter(){ super("Game Selector"); JButton Close = new JButton("Close"); JButton maze = new JButton("Maze"); JButton idk = new JButton("idk"); JLabel tell = new JLabel(" Please Select A Game"); GridLayout Lay = new GridLayout(4,2); setLayout(Lay); add(tell); add(maze); add(idk); add(Close); this.setSize(400, 400); setVisible(true); Close.setActionCommand("Close"); Close.addActionListener(this); maze.setActionCommand("Maze"); ...

82. adding component(object?) to JFrame after actionPerformed    java-forums.org

Hi, I'm trying to make a board game called "Don't get angry" in Java and I need to generate a playing field with cells. The problem is I cant generate it right away the program starts but after user choose from optionbox the number of cells/number of players and then clicks "generate" button. So far I have JFrame with two JPanels ...

83. NetBeans JFrame Events help    forums.oracle.com

Well I think it should be foreground since it will be the only thing on the frame. Sorry, I thought this was an easy question; I'm a new to java and didn't know the level of difficulty. I'll try posting it on SWING but if you have suggestions they are very much appreciated

84. Implementing KeyEvents in a JFrame.    forums.oracle.com

First one (tip 72) tells you to override rootPane for JDialog but you can also do this for JFrame. You then regsiter the listeners on the Root Pane for the functions keys and they should work whatever the focus. The second (tip 69) tells you an old way that adds listeners to every component of the frame/dialog and so detects any ...

85. JFrame (GUI) - ActionListener/ActionPerformed issues    forums.oracle.com

I didn't post the errors because I received so many. I have posted as many as I can. The errors below are a few of the several lines I receive when pressing the compute JButton. I'm thinking it may be because a variable is declared wrong or I haven't called a class correctly but I can't find my error. Exception in ...

86. Why is "extends JFrame implements ActionListener" a bad design decision?    forums.oracle.com

Hey, I am studying Advanced Development in my final year at university, now revising for my exams. I have been given a set of questions to answer - one of them being the above question. Does anyone know the answer to this, or can someone point me in the right direction to find the answer? I think it has to do ...

88. Executable JARs, JFrames, and ActionListeners    forums.oracle.com

The JAR file contains a public static main void class, one class for each of the two JFrames, two exception classes, one class for my custom data structure (tested extensively with JUnit), a jpg for the icon image that does not load when the JAR is executed (which leads me to believe you are correct in suggesting getResourceAsStream), and many txt ...

89. Event Fire When User Presses The "X" On JFrame?    forums.oracle.com

A class can not extend more than one base class. You can either implement WindowListener (no limit on number of interfaces implemented), or write a new class that extends WindowAdapter. I would go for the second, because I think you are listening to the window and to the mouse for different reasons, so why stick unrelated code together in one class? ...