Listener 1 « Event « Java Swing Q&A





1. How can I use listeners to access other elements?    stackoverflow.com

I'm setting up a GUI where I need to take information inputted from form elements and manipulate the information. This requires me to use some elements to access others. For example, I ...

2. Problem with keylistener    stackoverflow.com

hi i'm using swing and in my main frame(JFrame) i want that when ever user press + key one window lets say test should appear. my key listener works fine if i ...

3. How resource intensive are Listeners in java?    stackoverflow.com

I'm new to Java Programming but an experienced C++ programmer. I was learning how to program GUIs using swing. I was wondering how resource intensive (runtime as well as memory) ...

4. writing global listener    stackoverflow.com

I want the active window (i.e JFrame ot JDialog) to receive specific keyEvent so that whereever the focusing this keyevent is handling by the window such as ALT+F4 if you press it ...

5. How to resolve swing listener memory leaks?    stackoverflow.com

Background So I read that often memory leaks within Swing applications originate from the use of various listeners (mouse, key, focus, etc). Essentially, you register an object as a listener and forget ...

6. Why keylistener is not working here?    stackoverflow.com

i have implemented keylistener interface and implemented all the needed methods but when i press the key nothing happens here, why?

package swing;
    import java.awt.Color;
    import ...

7. swing: event listener support class    stackoverflow.com

Is there any preexisting class that helps support add/remove EventListener operations? (kind of like PropertyChangeSupport) I'm trying to partition my code into a model and view in Java. I have some data ...

8. mouse listener event    stackoverflow.com

I have got a program having an array of buttons, each of these button has their mouselistener event. Now, how can i find which of the buton is clicked through the mouse ...

9. Java/Swing: Problem with key listener    stackoverflow.com

I have a search dialog with a JTextField that's being used as a search box. When the user types something, it searches the DB, shows the result in a JTable and selects ...





10. Beginning with event listeners    stackoverflow.com

I have a simple app, showing picture made of tiled images(named u1, u2,...,u16.jpg). Now I'd like to add some Events to it, so that I can show these images only when ...

11. Create Listener similar to MouseListener    stackoverflow.com

I want to create a listener that works like mouselistener, but it must be a component: F.e. i have two JComponents (One is a button, and second is MyComponent), and i want ...

12. When to use EventListenerList instead of a general collection of listeners    stackoverflow.com

When I learned how to fire events in Java, I became familiar with EventListenerList. When I create my own listeners, I write the listener so it extends EventListener, I store them ...

13. Java Swing - KeyListener    stackoverflow.com

How can I know when the key typed change my text? Or if the key is a char?

14. Java action listener question    stackoverflow.com

I am creating a custom JPanel element (a login form). I want to allow people who use my panel to subscribe/listen to an event called "loginSuccessful". What is the best way to ...

15. In Java/Swing, is there a way to legally "attempt to mutate in notification"?    stackoverflow.com

I was wondering if there is some sort of magic I can use to get around an IllegalStateException and allow a JTextField to "attempt to mutate in notification", or in other ...

16. Custom Java Mouse Listeners?    stackoverflow.com

First off, I came to Java as a website programmer. In JavaScript, all you have to do to add a mousemove, mouseover, or click event is call an addEventListener function. From ...





17. java item listener    stackoverflow.com

i need help regarding the save menu item i have in my menu bar. i have set the code to

private void smActionPerformed(java.awt.event.ActionEvent evt) {


}
but i am unsure what needs to ...

18. Problem with basic listener behaviors in Java    stackoverflow.com

It's a little embarassing to not know how to fix this on my own, seeing how I have a bit of experience with Java, however until now I've never really done ...

19. action listener in another class - java    stackoverflow.com

it is possible to have two class, and in one something like

arrayButtons[i][j].addActionListener(actionListner);
and in another
ActionListener actionListner = new ActionListener() {
        public void actionPerformed(ActionEvent e) {

 ...

20. is there a NO MOTION mouse listener?    stackoverflow.com

I have a map applet, and I have a JLabel following the mouse, whenever the mouse goes over a city the JLable displays the the name of the city and population. I ...

21. KeyListener not reacting    stackoverflow.com

Im trying to use a KeyListener to do something when the button m is pressed, it needs to add an image to a JPanel, however it doesn't do anything :/ I use ...

22. Setting action listener on system applications    stackoverflow.com

How can I set the action listener on system applications? What I want is: when I start writing on the notepad, my action listener should detect it and I should be able ...

23. Java GUI listeners without AWT    stackoverflow.com

I am a starting Java developer, learning just from internet tutorials. I am learning full screen GUI applications. I was told yesterday that I shouldn't use AWT in my programs, because ...

24. My program's Action Listener won't work    stackoverflow.com

It's me again and I just can't seem to get this code to work. I'm basically asking for any advice on why the button does nothing when clicked. Would you like ...

25. Java Swing - Change JComponent opacity from mouse listener    stackoverflow.com

Pretty much like the title says - I've got a JPanel, and I'd like to have it at 90% opacity if inactive, and full opacity if moused over. I've got the separate ...

26. ComboBoxModel events not working    stackoverflow.com

I seem not to grasp the concept of Events and such. After reading a while on how to implement the listeners and such I came across the Java tutorial saying I ...

27. Listener invokes another listener    stackoverflow.com

In a class which creates a menu using Swing I have added 4 items, each one of them is responsible for drawing a circle of different color. I have assigned to ...

28. The Single Responsibility Principle and Event Listeners    stackoverflow.com

I'm currently trying to develop a simple GUI notepad to increase my skills in OOP. I stick to the Single Responsibility Principle while developing. I've divided the application into several parts following the ...

29. listener element overhead in non-GUI mode.    jmeter.512774.n5.nabble.com

Hello - Quick question on listener element overhead when running in non-GUI mode. I have a JMeter testcase that runs a fair bit of load (900 threads x 30 loops per thread x 2 samplers = 54000 requests). This always runs in non-GUI mode. The max JVM heap memory allocated is about 1 GB. However, I am ...

30. No listener in batch (non-gui) mode    jmeter.512774.n5.nabble.com

I'm using a custom listener to send results to another application. When I start a test plan in non-gui mode, the listener doesn't seem to be getting called. Is this expected behavior? Is it possible to create a listener that does get called in non-gui mode or am I missing something simple? --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden ...

31. Running listeners in non gui mode    jmeter.512774.n5.nabble.com

What are you trying to do? Visualizers are not run in non-GUI mode... On 07/09/06, duciuc <[hidden email]> wrote: > > Is it necessary to implements new Listetner in package > org.apache.jmeter.visualizers in order to run it in non gui mode? > -- > View this message in context: http://www.nabble.com/Running-listeners-in-non-gui-mode-tf2231850.html#a6186377> Sent from the JMeter - Dev forum at Nabble.com. > > ...

32. 'Global' keylistener    coderanch.com

33. KeyListener() is sometimes deaf    coderanch.com

This newbie needs some help from the 'old hands'. Context: The task of the small program is to display a worldmap image and then to read some data files with vector data to be drawn on top of the image. The approach (mostly plagiarized from "Just Java 2") is to: instantiate a JFrame instantiate a JPanel instantiate an ImageIcon with the ...

34. Listener in a listener    coderanch.com

36. Need help with event listener ->    coderanch.com

Hello all Swing/AWT freaks out there! The problem I am trying to solve in the middle of the night (it's 2.15 am here in Sweden), is that I have a JButton in a JFrame. When this button is pressed an Event is raised which I have delegated to a sperate event listener class. When this particular event arises I want the ...

37. event listeners cleaned up properly?    coderanch.com

Whenever I create any type of GUI component, it normally has one or more event listeners attached to it. I add all of these using addXXXListener() etc. When the component gets garbage collected, does the reference to the event listener get left somewhere, meaning that the event listener object will never get cleaned up until the program finishes? Should removeXXXListener() be ...

38. Key Listeners    coderanch.com

import java.awt.*; import java.awt.event.*; class TestKeyPress extends Frame { public TestKeyPress() { addKeyListener( new KeyAdapter() { public void keyTyped( KeyEvent ke ) { System.out.println( "Key was typed" ); } public void keyPressed( KeyEvent ke ) { System.out.println( "Key was pressed" ); } public void keyReleased( KeyEvent ke ) { System.out.println( "Key was released" ); } }); setSize( 100, 100 ); setVisible( ...

39. KeyListener reading    coderanch.com

40. Aren't Listeners very strange creatures?    coderanch.com

Playing around with listeners here I've noticed that when you're checking for modifiers, the listener still gets invoked twice. Typing ALT-6 for example : The listener gets modifier ALT and key ALT the first time. The listener gets modifier ALT and key 6 the second time. I suppose this makes sense but it seems messy when you're doing one check for ...

41. Can I have listener on the table header?    coderanch.com

Hi Samuel, Yes, some idea. Replace MouseMotion with MouseClicked and you have a great example. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class JTableHeaderListener extends Frame { private JTable table; private DefaultTableModel dtm; public JTableHeaderListener() { setSize( 500, 500 ); dtm = new DefaultTableModel( 5, 5 ); table = new JTable( dtm ); JScrollPane sp = new JScrollPane( table ...

43. Listener not getting message?    coderanch.com

44. "Global Fields" used in listeners    coderanch.com

I have a gui that uses a couple ActionListeners to respond to button clicks. Within those listeners, I use values entered in fields on the JFrame. I'm currently creating the listeners as inner classes and making the text fields private class variables so the listeners have access to them. I'm concerned about this approach because I'd rather have the text fields ...

45. Listener Classes    coderanch.com

I have several class files in my SWING GUI. Some or even all may contain JCheckBoxes, JRadioButtons, etc. Components that require a listener. Anyway, I want to have only one Listener Class for each Component. For instance, I may have 3 classes that use a JCheckBox and I want only one MyCheckBoxListener Class to listen for all the checkboxes in my ...

46. One strange question about listener    coderanch.com

Hi Walter, That is because you are overriding the processWindowEvent method. The default functionality is to notify all the component's registered listeners. Since you are overridding that functionality and not performing it the windowClosing method will not be called. By calling the parent processWindowEvent you are restoring the default functionality. It is not normal to override processXXXXEvent methods unless you want ...

47. Listeners And OOP    coderanch.com

Hi Ray, The easiest approach would be to have the SomeGUI handle the button clicks. If it requires a handle to MasterFrame then you need to pass it into the SomeGUI constructor and keep a copy of it as a private class variable. For example: class SomeGUI extends JPanel implements ActionListener { private MasterFrame mf; public SomeGUI() { this( null ); ...

48. Is there another way to implement event listener (in general)?    coderanch.com

Hi all, I am having this feeling over and over when i need to attach a listener to a particular Container. When i create an applet or a frame with text fields and buttons, i have to implement the event listener on the applet/frame. If i want to create another class to implement the event listener, this class has to be ...

49. Global keylistener    coderanch.com

50. keyListener in java    coderanch.com

51. Listener and adapter class    coderanch.com

52. keyListener    coderanch.com

53. Generic Tag Listener - Request for Comment    coderanch.com

Hello, I have developed a GenericTagListener class which (I Hope..) will help developers who frequently need to use JTrees in combination with other components in their GUI's Basically the idea is that there are 3 maps 1. Component Map 2. Value Map 3. Component Type Map In the component map you register a component key with a component. In the value ...

54. confusion in the Item listener    coderanch.com

iam using a item listener for a jcombobox that is used in a particular column of a table! the combobox contains only two elements " yes" and "no" i need to display a message when eigther of "yes" or "no" is selected. the confusion is when i press a cell of the particular column in the table, a message box is ...

55. Action Listeners    coderanch.com

Hi, I have code with a Check Box in an applet. Even when the box is checked the the output still says it is false. Meggsy import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class HotelApplet extends JApplet { private JLabel CNameLabel, CustomerTitleLabel; private JTextField CNameText, CAddressText, CIdText; private JButton printBut, resetButton; private JTextArea printDetails; private JComboBox CTitleCombo; private String ...

56. listener problems    coderanch.com

57. Listeners the pro way...    coderanch.com

58. Action Listener    coderanch.com

Thank you this works fine for me. Are you interested helping me with another matter ? If you are please read on I am now trying to save the contents of Ausgabe but I am not sure if Iam using the right method the Speichern is the save method here is the changed code import java.awt.*; import java.awt.event.*; import javax.swing.*; import ...

59. The best approach for event listener    coderanch.com

It depends on what you are trying to do, but personally, the first version is much more readable, and should be OK to use in the majority of circumstances. Probably the *worst* designed GUIs I have seen have been from the code created through visual GUI creators, so I would definately not try to learn good coding habits from code generation ...

60. KeyListener    coderanch.com

import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; public class KeyRegister { static JPanel panel; static Random r; public static void main(String[] args) { r = new Random(); panel = new JPanel(); panel.setBackground(getNewColor()); panel.getInputMap().put(KeyStroke.getKeyStroke("W"), "COLOR"); panel.getActionMap().put("COLOR", color); JFrame f = new JFrame("Press \"w\" Key For Color"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(panel); f.setSize(400,300); f.setLocation(200,200); f.setVisible(true); } private static Action color = new AbstractAction() { public ...

62. keyListener problem    coderanch.com

63. How to write my own Event ( & Listener for it)??    coderanch.com

Take a look at this receipt: 1. Create the class MyEvent. It must extend EventObject. //------------------------------------------------------------ //file MyEvent.java import java.util.EventObject; public class MyEvent extends EventObject { public MyEvent(Object source) { super(source); } } //_______________________end file 2. Create the listener class. It must extend EventListener. //------------------------------------------------------------ //file MyEventListener.java public interface MyEventListener extends EventListener { public void myEventOccurred(MyEvent evt); } //_______________________end file 3. ...

64. Splitpanes and Listener    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*; public class Communication { public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new CommunicationPanel()); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } } class CommunicationPanel extends JPanel { JTree tree; JTable table; String[][] headers; JScrollPane tableScroll; JLabel[] formLabels; public CommunicationPanel() { createTree(); createTableInfo(); tableScroll = new JScrollPane(); tableScroll.setPreferredSize( new Dimension(tableScroll.getPreferredSize().width, 200)); ...

65. KeyListener    coderanch.com

I have an application that is set up like this, the main frame is a jframe, I have a menu bar on it and two jpanels on the inside of the jframe, one to hold the textfields and one to hold my buttons, previous and next. I want to add keylisteners to the application so that when you press the right ...

66. Listeners execution    coderanch.com

67. Events and Listener List    coderanch.com

68. key listeners..    coderanch.com

69. problem with listener    coderanch.com

import javax.swing.*; import java.awt.event.*; import java.awt.*; public class CTRL_Vis_StudInfo implements ActionListener { private GUI_Vis_StudInfo2 gvs; private DBFasadeStudent dao; String valg="i"; public CTRL_Vis_StudInfo(GUI_Vis_StudInfo2 gvs){ this.gvs = gvs; } public void actionPerformed(ActionEvent e) { if (e.getSource() == gvs.getRadionr()) { System.out.println("nr"); valg="n"; System.out.println(valg); gvs.getSok().setText("Ske etter student-nr:"); gvs.getSokButton().setVisible(true); } if (e.getSource() == gvs.getRadioFornavn()) { System.out.println("fornavn"); valg="f"; System.out.println(valg); gvs.getSok().setText("Ske etter fornavn:"); gvs.getSokButton().setVisible(true); } if (e.getSource() == ...

70. listener dead?    coderanch.com

hi, i have 1 GUI class that has buttons, and the listener is in the CTRL class. they are somehow connected with each other. but nothing happens when i do something with the GUI. public class GUI_Vis_StudInfo2 extends JDialog{ HoyreStud hoyre = new HoyreStud(); VenstreStud venstre = new VenstreStud(); SorStud sor = new SorStud(); public GUI_Vis_StudInfo2(JFrame f, boolean b, DBKobling k) ...

71. text listeners    coderanch.com

72. Problem in Relation to Action Listener    coderanch.com

73. inherited vs. implements Listeners    coderanch.com

74. Mouse Listener Problem    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Events { JDialog dialog; JLabel label; public Events() { JFrame f = new JFrame(); prepareDialog(f); JTable table = getTable(); table.addMouseListener(new TableListener(table)); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(getUIPanel(table), "North"); f.add(new JScrollPane(table)); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } private void prepareDialog(Frame f) { label = new JLabel(); label.setHorizontalAlignment(JLabel.CENTER); dialog = new JDialog(f, false); dialog.add(label); dialog.setSize(300,200); dialog.setLocationRelativeTo(f); } private void launchDialog(JTable table) ...

75. Listener/Events Help    coderanch.com

Hi, I am pretty much a swing/awt newbie but feel I have a good grasp on Java itself. I am designing a log in type window and have the text fields and buttons layed out. I want the program to do something(right now just print the contents of the text field to standard output) when I click the 'OK' button. When ...

76. Probelm with KeyListener    coderanch.com

77. KeyListener Issue    coderanch.com

78. KeyListener woes    coderanch.com

I would like this program to move a picture around the screen as someone presses the arrow keys. The problem is, I can't get the KeyListener to listen to keys while it's looping in my page flipping loop. There is a MouseListener attached to my window that works great. However, the KeyListener I added doesn't do a thing. I've tried a ...

79. Doumnet Listener Problem    coderanch.com

80. KeyListener Problem    coderanch.com

81. problem in two listener??????    coderanch.com

hi all the problem arises due to two listener first one is Document Listener and another is the Caret Lisstenet, i used Caret listenet to treet my coded special characters "<>" as a single character when i click in between then the cursor goes to the end of <> but problem arises in two case 1> when i select one or ...

82. how to use a listener    coderanch.com

hi, i am using swt/jface. i am using mvc architecture. the problem is that i have a class called application which contains menuitem 'show details/hide' whose text toggles. i have also a buton 'show detail/hide' which is defined in another view class and the button action is defined in an controller class. the view is bined to controller. the controller is ...

83. listeners    coderanch.com

84. Key Event listener question.    coderanch.com

Could someone explain to me how to make a Key Event Happen. I have done some button listeners for example. usernameButton.addActionListener(new UsernameButtonListener()); Do I set up a key event the same way? If so what is the correct syntax when doing this? I then have my actual even for the button listener as follows: public class UsernameButtonListener implements ActionListener { public ...

85. How will I create a common key listener?    coderanch.com

Hi, everybody! I am coding a simple form which is attached to a table. My jtextfields take its values from the corresponding columns of the table. My question is how can I make a common key listener which listens to a PageUp or PageDown keypress from ANY of the jtextfields which signals that I should navigate accordingly through my resultset. What ...

86. Swings, Event Listeners & OutOfMemoryError: Solutions?    coderanch.com

Something I just read by Tony Morris in the advanced forum struck a chord with me. You start a VM with 256MB heap, and during operation it averages about 80-100MB heap, until it gets to one certain piece of resource intensive code that attempts to allocate 200MB, which of course, results in a OOME. What do you do? Shut down and ...

87. KeyListener && KeyEvents    coderanch.com

Hello , My problem had two various things. 1- I wanna dedect when tab key is pressed or typed or released. i tried ; public void keyPressed(KeyEvent ke) { System.out.println("keyPressed"); if (ke.getKeyCode() == ke.VK_TAB) { System.out.println("tab-keyPressed"); } } I dont even get the first message when i type tab key. Its moving to another focusable component and seems No Keyevent fired. ...

88. Listener for doubleclick    coderanch.com

89. TextViewer, StyleRange, Listener    coderanch.com

90. Key Listener    coderanch.com

ok here is a snippet of my code in one of my JPanel constructors... KeyListener ShipListener = new KeyListener(){ public void keyPressed( KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_UP) System.out.println("up pushed"); if(e.getKeyCode() == KeyEvent.VK_DOWN) System.out.println("down pushed"); if(e.getKeyCode() == KeyEvent.VK_LEFT) System.out.println("left pushed"); if(e.getKeyCode() == KeyEvent.VK_RIGHT) System.out.println("right pushed"); repaint(); } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} }; this.addKeyListener(ShipListener); ok for some reason, ...

91. KeyListener working randomly    coderanch.com

I have a program that the key listeners only work at random. When I start the program they work sometimes, and sometimes they dont work. my code is as follows private void setUpListeners() { Container clientArea = getContentPane(); clientArea.setFocusable(true); addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_UP ){ rightPaddleMovementStatus = MOVE_PADDLE_UP; } if(e.getKeyCode() == KeyEvent.VK_DOWN ){ rightPaddleMovementStatus = MOVE_PADDLE_DOWN; } ...

92. listeners    coderanch.com

I am having trouble attaching listeners to my gui. Here is my my code for the guipublic class ParserGUI extends JFrame { public ParserGUI() { super("Lisp Function"); setBounds(XOFFSET,YOFFSET,XWIDTH,YHEIGHT); setDefaultCloseOperation(EXIT_ON_CLOSE); input = new JTextField(20); in = new JLabel("input"); output = new JTextField(10); out = new JLabel("output"); text = new JPanel(); text.add(in); text.add(input); text2 = new JPanel(); text2.add(out); text2.add(output); calc = new JButton("Calculate"); ...

93. JSpinner arrow listener    coderanch.com

not sure I understand the question, but this will give you access to the arrow buttons import javax.swing.*; import java.awt.*; import java.awt.event.*; class Testing { public void buildGUI() { JPanel p = new JPanel(); JSpinner spinner = new JSpinner(new SpinnerNumberModel(50, 0, 100, 5)); spinner.setUI(new MyUI()); p.add(spinner); JFrame f = new JFrame(); f.getContentPane().add(p); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } public static void main(String[] ...

94. those crazy listeners!    coderanch.com

95. How do I get this listener to wait for this other listener?    coderanch.com

I am working with a "Frame" object (see below) which I am not allowed to modify. The JButton in this Frame has its own listener. I need to add a new ActionListener to this button in order to expand its functionality. I can't get this to work the way I want it to, and I think it's due to a synchronization ...

96. Class implements Listeners    coderanch.com

You wouldn't notice the efficiency difference. There might be a few milliseconds, but when you take maybe 0.3seconds to click a button, that is an imperceptible delay. What I think you would notice, and I have fulminated about it on these fora before, is a maintenance overhead. BTW: There is a link in the most recent Java Developers' Network newsletter to ...

97. Listeners and GC    coderanch.com

When adding listeners to components (e.g. addActionListener), do we need to remove them explicitly afterwards, or will the garbage collector clear them properly when a window is closed ? I'm using a profiler and it seems that the listener stays around unless I explicitly remove it from its source. If anybody could share some light on this. [ March 29, 2007: ...

98. Focuslost listener for TableViewer    coderanch.com

I have an editable tableviewer. I want to sort the rows with the date value entered in the columns but when the user has lost focus on the row i.e. I want to do the sorting when the user has clicked onto a different row. How do I add a focuslost listener to a TableViewer. Thanks for any help.

100. Events listener are not working.    coderanch.com

I have three events which are passing parameters: a,id and scale. The drawing is successful except listener no responses. I guess I missed something, but where is it? Please advise. Thanks. import java.io.*; import java.util.List; import java.util.ArrayList; import java.util.LinkedList; import java.util.ListIterator; import java.util.Scanner; import java.awt.Font; import java.awt.Color; import java.awt.Graphics; import java.awt.BasicStroke; import java.awt.GradientPaint; import java.awt.geom.GeneralPath; import java.awt.AlphaComposite; import java.awt.Composite; import java.awt.geom.*; ...