Click « Button « Java Swing Q&A





1. event attached with button clicking    stackoverflow.com

I have a JFrame in which there are 2 textfields and 1 JButton. Users need to enter some string in the textbox. When user clicks the button in the JFrame then ...

2. Right click on JButton    stackoverflow.com

I am trying to write a Minesweeper clone in Java for fun. I have a grid of JButtons whose labels I will change to represent the danger count, flags, etc. ...

3. Java Swing; is there a way when clicking a button, a popup will appear NEXT TO THAT BUTTON    stackoverflow.com

I have a JButton that has a callback function like so:

myJButtonCallBackFunc (ActEvtListener evt) {
    myFrame.pack();
    myFrame.setVisible(true);
}
The myFrame pops up on the upper left hand corner ...

4. how to exit upper frame by click on ok and how to add back button when two page in single frame    stackoverflow.com

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Prhr extends JFrame implements ActionListener,ItemListener
{
    JLabel l1;
    JLabel l2;
    JTextField ar;
    JTextField t;
 ...

5. JButton referring to space bar the same as a click    stackoverflow.com

JButtons consider pressing the space bar to be the same as clicking on the JButton (assuming the JButton has the focus, which I am assuming here). Is there a way ...

6. how to close a frame when button clicks    stackoverflow.com

I am new to Java Swing. I am creating a frame with some components. I have to close the frame and open another frame when the button is clicked. I had tried ...

7. How to launch an .exe file by clicking a JButton in GUI?    stackoverflow.com

I've created a JFrame with 3 Jbuttons. I'd like the button to launch different .exe file located in the same folder. Is this possible? If yes, what should i write for ...

8. jButton responds only to second click (Netbeans 6.9.1, Java)    stackoverflow.com

I have an annoying problem, and I don't seem to understand where in comes from. I have an application and a simple UI for it. The problem is that when ...

9. Programmatically clicking a GUI button in Java Swing    stackoverflow.com

How would I programmatically click a Swing JButton in a way that would register all the relevant action/mouse events and be visible to the user (i.e. they'd see the button being ...





10. Java: How to show Hello World! after button has been clicked    stackoverflow.com

I would like to learn how you go to a next 'frame or screen' in Java. I'm learning Java and got the Hello World App working, My next step is to have a ...

11. Java Swing; how to show text after button is clicked    stackoverflow.com

I want 'Hello world!' to show when my button is clicked. So go to a next 'frame' but in the same window! I tried card lay-out, but can any one tell me ...

12. How do I Click a JButton without Clicking it?    stackoverflow.com

I have a JButton and when a player clicks it it tell my Action Listener that a button is clicked. What i want to know is that is there a command ...

13. How to wait till one of the buttons is clicked?    stackoverflow.com

I am working on a project and have stuck at a point. I am working with Java Swing and this is the Problem: When the user clicks on readMore button, I am ...

14. Is there a way to limit user to click a jbutton once in java    stackoverflow.com

If in a card game i only want to the user to click the deal button once.

15. Change contentpane of Frame after button clicked    stackoverflow.com

I want to be able to set a JFrame's contentpane after a button inside one of that frame's JPanels has been clicked. My architecture consists of a controller which creates the JFrame ...

16. Java Swing - modification of variables/other swing objects on button click    stackoverflow.com

Ok so basically im struggling to perform some actions with Java Swing JButtons. I have a feeling that my problem is an ease for skilled programmers so bare with my "elementary" ...





17. using infinite loop in a button click event    stackoverflow.com

Is there any known problem if I use an infinite for loop within a button click event? Actually, first I set up the program by taking settings from the GUI. Then ...

18. Open new tab in frame other than the frame where button is clicked    stackoverflow.com

I have 2 frames. One contains buttons that do appropriate actions on data. And secnd frame which contains data in tab view. Now I have to add one button in first frame ...

19. Java UI, trying to go to next page upon clicking button    stackoverflow.com

I have a simple GUI with 3 radio buttons and a button. I want the user to select a radio option, then upon clicking the button the user will be ...

20. Validating contents on Next button click in jWizard Framework    stackoverflow.com

Here is my problem. I wanted to implement an "installation wizard" in Swing. I stumbled upon jWizard framework and I liked the look-and-feel of the wizard. Unfortunately, I have ...

21. Handle JButton click event in another class    stackoverflow.com

I'm new to java coming from C# so I'm not familiar with java best practices. I have a main class that opens a JFrame to get several input strings from a user. ...

22. How can I find out which button was clicked?    stackoverflow.com

I've got my buttons working right, and I'm a listener to each button like this:

for(int i = 0; i <= 25; ++i) {
    buttons[i] = new Button(Character.toString(letters[i]));
  ...

23. Swing: Click on a button in a frame, show another frame with different components    stackoverflow.com

I am developing an application which needs to pop up new JFrame B with different components, when I click on a button on JFrame A. How do I achieve that? I ...

25. Open browser when u click a button    coderanch.com

28. Serious Problem with Double click of JButton..    coderanch.com

Developers, im having some serious kind of problem , with JButton Double click . what i need when some user double clicks (or by pressing enter key very fast 2 times ) the action behind the listener for that button is executed two times that is not desied because it has some financial transactions behind it and aloowing user pressing button ...

30. Open browser on button click    coderanch.com

31. opening a text file in wordpad from a button click    coderanch.com

wordpad isn't in your PATH, so you'd have to specify where wordpad is. It's just like going to the command prompt and typing: wordpad.exe filename It gives you an error right? On the other hand, if you were to type: \path\to\it\wordpad.exe filename it would work. So you have to do the same thing programmatically. Or add the directory containing wordpad.exe to ...

32. Help Me Click the Default Button    coderanch.com

Hi, I've got a popup control to capture a password. However, I can't get the 'OK' button to be the default button such that when I type in a password and hit enter, the OK button would be clicked. Instead, I have to tab out and hit space, or I have to click it with the mouse button. I've tried many ...

33. Button Click Event    coderanch.com

import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class ButtonTest extends JFrame implements ActionListener { JButton b = new JButton ("Press me twice"); static long oldctm = System.currentTimeMillis(); ButtonTest (){ Container c = getContentPane (); c.setLayout (new FlowLayout ()); c.add (b); b.addActionListener (this); pack (); setVisible (true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent ae) { long ctm = System.currentTimeMillis(); long dif_ctm ...

34. Double click as a single click on JButton    coderanch.com

Hi Anne Just playing to see how far I could go overriding system double click wait for slow double clickers. import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class ButtonTestTwoAsOne extends JFrame implements MouseListener { JButton b = new JButton ("Press me twice"); static long oldctm = System.currentTimeMillis(); final int maxDoubleTime = 1000; ActionListener waitOneClickCount = new ActionListener () { ...

35. How 2 Run exe when button clicked    coderanch.com

37. how to simulate a button click    coderanch.com

My actual problem was, to access the local file system in an applet. I found the code on the net, signed it and it works fine. But when I do the equivalent of what the code si doing in my own public method, creating new file and all, I get a permission denied exception. Any pointers regarding this? doClick is raising ...

38. four digit counter up/down on button click    coderanch.com

Dear All The figure shows a counter, which can be operated using a button called up/down button.Can anybody help me to find a logic to do this.It should incremnt the value from 1 to 9 then 10 sould be writen as 1 and 0 on defferent fields. |--------|-------|-------|-------| | | | | | | 0 | 0 | 0 | 0 ...

39. How to close the Frame by clicking the Esc Button?    coderanch.com

Hi, I have one problem in Java Swings. I have a one main window which is a frame and that contains three buttons, If I clicked one Button, It has to open a new Jframe window. The other Two buttons are such as Save and Cancel. The new Window also contains two buttons such as Save and Cancel .Now if I ...

40. Open Help(.chm) File on click on Button    coderanch.com

41. Button click - String operation    coderanch.com

I have a window in which the user enters their information, which is then recorded to a file. Everything works except for the string comparison (.equals(), in bold); it didn't start to give this error (also shown below) until I added that line and another piece of code I wrote is having the same problem. I can't figure out what the ...

42. Open outlook express on JButton click    coderanch.com

43. Refreshing a list on button-click    coderanch.com

> I understood this concept but in swings i don't know if anyone knows please give me the example, well, if you understand the concept, and you're not sure if anyone else does, why don't you give the example??? [edit] perhaps a missing comma after "but in swings i don't know" changes the intent of the post. if so, change the ...

44. Click button to close popup window    coderanch.com

private void createCridPopup(String crid) { if (cridPopup == null) { cridPopup = new JDialog(JOptionPane.getFrameForComponent(this), "Confirm Crid", true); cridPopup.getContentPane().setLayout(new BorderLayout()); JPanel p1 = new JPanel(new GridBagLayout()); JPanel p2 = new JPanel(); p1.add(new JLabel("Confirm Crid",JLabel.RIGHT)); p1.add(txComfCrid); p2.add(bnCridOK); cridPopup.getContentPane().add(p1, BorderLayout.NORTH); cridPopup.getContentPane().add(p2, BorderLayout.CENTER); //cridPopup.setLocation(500, 500); cridPopup.pack(); txComfCrid.addActionListener(this); bnCridOK.addActionListener(this); cridPopup.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); cridPopup.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { bnCridOK.doClick(); } }); cridPopup.setSize(new Dimension(250,100)); cridPopup.setLocation(700, 200); } ...

45. to show a video on button click    coderanch.com

46. To change the colore of the clicked Jbutton    coderanch.com

I have been devoloping a TIC TAC TOE applicaton i know how to make the button disabled by marking the users or computers mark but i dont know how to change the colore of the button when it is clicked buttons.setText("O"); buttons.setEnabled(false); this is how i have been doing that i tried buttons.setBackground("color.red") but it says setbackground function not found in ...

50. Shortcut key for button click    coderanch.com

51. Freeze the GUI on a button click process.    coderanch.com

Dear all, I am having a GUI where i will be having four or five buttons more than that i will be having a tree also. For each button there will be an action called, on the same time in the tree also on selecting each node of the tree an action will be performed. But for me the requirement is ...

52. Right-clicking a Button or JButton    coderanch.com

Brian Cole wrote: By that I mean that if the user right-presses on the button, moves the cursor outside the boundary of the button, then releases the button that no event should be fired. I see what you mean but it's a different concerning Minesweeper. Note that right-clicking places a flag on a square. If you play Minesweeper of Windows Vista ...

53. Clearing old widgets and creating the same again on a button click    coderanch.com

Hello ranchers, On a button click i am creating a table on a composite. and wen i click agen i want to dispose this table and create again. because everytime i click the button, new table gets created keeping the old one already on composite. Hope I am clear. Thanks, Madhavee Latha

55. Buttons without clicking animation    coderanch.com

I'm making a battleship game, and I need to make a grid where the user can click to select where their ships are supposed to be and fire at enemy ships. Basically I need a button for each cell in the grid but not a button where it has the clicking animation, just a flat cell that puts a dot in ...

56. Click on button then a second button    coderanch.com

So far I can create the buttons, but I can only achieve one button click at a time. I want to be able to click one button and click on a second button; each button will hide a picture then I will need to compare the pics . I am probably not explaining it clearly however this example in this link ...

57. invoke shell script, by clicking on swing application button    coderanch.com

> I need the code, from swing application to invoke and run shell script automatically. please i am very new to java swing.... please it's very urgent for me... > I am very newer to java/swing. could you plese send me the code ""how to invoke shell script from swing"... just started on the help desk?

58. Highlight the button which need to be click, in swing applicaton..    coderanch.com

B.V.S. Ramakrishna wrote:My thing is, my swing application have 4 buttons.my wish basically it highlight's the first button. when we click on it it shows the progress bar, after the progreasss over,it need to highlight the second button like that. Can you post a small program that shows what you are trying to do? Also, most important (and still not stated), ...

59. JButton - Click & Drag prevents Event    coderanch.com

60. How to know which button being clicked?    coderanch.com

I also post my problem in dreamincode.net and stackoverflow but haven't get my problem solved. I'm trying to make N x N grid of JButton with one JTextField in the below where we can input character there then clicked on any of the white button to make the input show up on the button that being clicked. Is there a way ...

61. When click on minimize button then it must goes to System Tray?    coderanch.com

When anyone click on minimize or close button of window then it will go to Taskbar Status Area. And when we click on close button then window will close but application don't close means it show icon in Taskbar Status Area. Like as gtalk.when we click on close button of gtalk window then window goes to system tray .And gtalk application ...

62. to change the button picture present in the resources folder in netbeans on click    coderanch.com

Hey guys i have worked on 1 or 2 small assignments in swings . I am currently trying to develop a Burglar Alarm System . so i need to use buttons to start the system and shut it . so i have 2 .png image files in my resources folder in my netbeans project . so the button is default with ...

64. clicking the X button does not close a netbean developed app    coderanch.com

Hey I am using netbeans to handle my GUI however when I click on the X button to exit, the window is gone but the application remains running in the background. However, going through file-> exit will close the whole thing. How can I capture the window close event or make sure the window is closed? I searched in the form ...

65. calling another swing application to run when a button is click from my swing application    coderanch.com

this is my code import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MyClass { public static void main(String args[]) { MyFrame mf = new MyFrame(); mf.setVisible(true); mf.setSize(400,400); mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } class MyFrame extends JFrame { public MyFrame() { MyFramePanel mfp = new MyFramePanel(); add(mfp); mfp.setSize(100,100); } } class MyFramePanel extends JPanel implements ActionListener { JButton OkBtn,exitBtn; JLabel name,address,phone; JTextField nameField,phoneField; JTextArea ...

66. clicking a button to show a popup using doClick() is not releasing the button - JFCUnit    coderanch.com

Hi All, I'm using JFCUnit to automate a Swing application. There are several screens on which I'm programmatically clicking on "Next" button which takes me to the next screen. I'm using the following code for that: JButton myButton = (JButton)JFCTestHelper.findNamedComponent(buttonName, appWindow, index); myButton.doClick(); The problem that I'm facing is, when I click on a non-next button of a screen, like a ...

68. Clicking works, but pushing "enter" return errors...how to fix? (on a button named "Enter")    coderanch.com

The problem: When I click "Enter", the program runs fine 100%. When I push "enter" when the "Enter" button has the focus, it returns errors. Everything else works 100% fine. Please help me with this problem: Risk.java: import javax.swing.*; import java.awt.*; import java.text.NumberFormat; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.*; public class Risk extends JPanel implements KeyListener, ActionListener { public int heck, ...

69. Click button is not function    coderanch.com

Hello I really need help. When I click the button, it don't point to other windows. Below is what I have done so far. Really appreciate if you guys can help me. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; class Menu extends JFrame implements ActionListener { private static final JFrame Menu = ...

70. Button click on the pop up should click button on another page    coderanch.com

Yes I don't really need a hidden button but it was my option. As the ComboBox and EnterButton are on two different pages and I didn't know a way to populate it on EnterButton click. I have all my logic on HiddenButton which retrieves data from the DB and populates the ComboBox working right now. So I though if I can ...

71. generate table data on button click    coderanch.com

Hi all, I am new to Swings. I have made a frame and I put a button in it. I have written some hard code data in my code which is displaying in my table. Now I want that data to be display in my table when i click on the button.Here is the code... Thanks package mypack; import java.applet.*; import ...

72. Find source of button click    coderanch.com

i have created an Image button and didnt know how to identify the button clicks by the user.. when i use getSource() method am receiving exception... If it is a normal button we'll be checking the button text...If it is a image button without any text what should be checked to determine the button clicked..? am confused...!

73. Minimize to tray on close button click.    coderanch.com

Hi all, I have made a jframe in which i am using setDefaultCloseOperation(HIDE_ON_CLOSE) operation. By this when i click on close button of window, frame simply hide and my tray icon doesn't disappear but when i click on Jbutton named as CLOSE, tray icon disappear because i have written System.exit(0) in button action performed method. Now I want that when i ...

74. [SOLVED] How to destroy a process when a button is clicked?    java-forums.org

hi all, I am running a Process in a background thread and i want to stop that process when i click on a button. i cudnt access the obj of Process from the button click event. i also tried to declare it as static but in vain. pls suggest me possible workarounds.

75. [SOLVED] Open a different class from the same package when button clicked.    java-forums.org

Hurrah!!! it worked :o Thank you so much dswastik, i've spent hours trying to get that work. I thought it had something to do with telling the program MainInterface is not in that class, I just didn't know how to write that in Java Syntax. Thank you to neeraj.singh, I now know how to assign multiple buttons to do different things; ...

76. how to click a jbutton and open an url    java-forums.org

78. How to make the actionPerformed be executed till the next Button click    java-forums.org

Hello EveryOne :) What i need do to is: To make the first if loop to be executed first then the switch loop be executed second. To keep clicking RNButton till the random number will be 1 at that point i want this line "The First Random Number is 1" to be printed, then the next line wont be printed till ...

79. SaveAs button click    java-forums.org

And in my code , it is working fine, but when i click save as button, save as dialog pops up and if i give an already existing file name, it throws an error dialog as "File already exists, do you want to replace?' and if i click CANCEL, the save as dialog again pops up and if i give the ...

81. Detecting the clicking of two specific JButtons to create an event    java-forums.org

Hello Everyone I am trying to make a java swing/awt app that is a basic simulation of a beverage vending machine. I need the program to recognise the clicking of two specific JButtons for a product code. For example if JButton 'E' was pressed then JButton '1' was pressed the program would know that is the code for soda and display ...

82. Buttons being clicked in certain order in GUI    java-forums.org

Hi, I'm quite new to Java and am doing an assignment where I have to create a GUI to represent a keypad system to enter a room. There are 9 buttons and the user must click 4 buttons in a certain order to gain entry eg button1, then button2, then button3, then button4. I can't figure out a way of coding ...

83. How to perform some event to button click    java-forums.org

84. JButton after a click    java-forums.org

Hello everyone, I've got a small problem. After I click on a JButton he gets bigger and I don't want it to happens. I attached 2 pictures that will demonstrate it. And here is also the source code, the code is long cause of the action listeners so don't panic :P Java Code: import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; ...

85. JButton click problem    java-forums.org

Java Code: //[b]activeTable() - check the Jcombobox' index and resize the right panel and hide other panel[/b] private void [b]activeTable()[/b]{ if(cmbTables.getSelectedIndex() == 0) { pnlStocks.setVisible(true); pnlStocks.setEnabled(true); pnlStocks.setSize(670, 220); pnlStocks.setLocation(6, 97); } else { pnlStocks.setVisible(false); pnlStocks.setEnabled(false); pnlStocks.setSize(1, 1); pnlStocks.setLocation(0, 1); } if(cmbTables.getSelectedIndex() == 1) { pnlReq.setVisible(true); pnlReq.setEnabled(true); pnlReq.setSize(670, 220); pnlReq.setLocation(6, 97); } else { pnlReq.setVisible(false); pnlReq.setEnabled(false); pnlReq.setSize(1, 1); pnlReq.setLocation(0, 1); } } ...

87. JButton click    java-forums.org

Hi, this question is actually a bit simple but I want to hear from you folks what is the right way to do this. I have a JButton which has shortcut key using key bindings I was able to do this but I am confuse if I should use actionListener for mouse click. What I did is add an actionListener and ...

88. Button click GUI question    java-forums.org

for (int i=1;i<10;i++){ final JButton button = new JButton("" + i, filler); add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ XO = (int)(Math.random()*3); if ( XO == 1) button.setIcon(showcross); else if ( XO == 2) button.setIcon(shownot); else button.setIcon(filler); } }); button.addActionListener(printButton); } } } static class PrintButtonClick implements ActionListener{ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand() + " was clicked."); } }

90. JButtons, Click    forums.oracle.com

My simplified perception of a combination lock is that you would have three buttons, each displaying a number. And as you press a button it would increment its value (and change the label on the button accordingly). You could store the values in an array. And after each click compare the values in the array to the required values to see ...

91. Refresh the jsp page on click on the Finish button of Swing application    forums.oracle.com

Hi All, I want to refresh the JSP page on click of the finishbutton on Swing application open from a browse button place itself on the jsp page with the help of JWS. Now I want to refresh the data present on the page as I process on the data on the swing application. But now i am unable to move ...

92. Help! correct++ if JButton is clicked    forums.oracle.com

93. To change the colore of the clicked Jbutton    forums.oracle.com

1) the problem is in the parameter you're trying to pass to the setBackground method. You're trying to pass a String. Please check the API and see what needs to go there instead. 2) next time you have a similar problem, I urge you to post it in the Swing forum. Good luck!

94. Multiple clicks using JButtons    forums.oracle.com

I am using JButtons to trigger events in an experiment and then logging data using the System.time method. However I seem to be getting multiple printouts when a button is only clicked a single time. I have setup the process using the ActionListener class and then have an if statement and a few else if's to determine when a button has ...

95. Detecting a left click on JButton?    forums.oracle.com

The "click" of a JButton is somewhat abstract: it may be triggered by the mouse, or by the keyboard. As noted, the ActionEvent that your program sees has no information about the mouse or its buttons. Perhaps you could use some other component: a JLabel, say, showing an Icon. If you add a listener you can detect when a MouseEvent occurs ...

96. JButton clicked    forums.oracle.com

97. JButton clicked problem?    forums.oracle.com

98. Obtain index of clicked JButton    forums.oracle.com

Hello alL I've an array of 11 JButtons. JButton[] btnC = new JButton[11]; I've added the JButton to the addActionListener. Then in the overrided ActionPerformed(ActionEvent ae) method i'm using the if (ae.getSource == btnC[0]) //set of actions How can I deduce which JButton was clicked. This i've todo for all the individual 11 buttons How can i obtain the index of ...