Button 1 « Button « Java Swing Q&A





1. Swing buttons don't react immediately! How can I change that?    stackoverflow.com

I've built a form with Netbeans's visual editor. When I press one of the buttons it should do the following :

  • set it to disabled
  • perform a task that takes some time
  • when the ...

2. The buttons are working but they are interacting with the compiler not the gui?    stackoverflow.com

Im guessing my buttons are right, but when clicked they add integers on the compiler and subtract integers using the next and previous buttons. i want them to scroll through the ...

3. Setting a button    stackoverflow.com

I have 2 buttons. One is "add". The other is "cancel". In the cancel button action, I want to write that until the add method is not called, this button do ...

4. Generic solution to deselect buttons in java    stackoverflow.com

In a set of radio buttons of the same group, only one can be selected at the same time. I would like to have the same behaviour with a normal button. Imagine ...

5. Java Swing blinking button sequence    stackoverflow.com

I'm trying to make a remedial simon says like game using Swing (Jframe/jbuttons/grid setup). At the moment I can't figure out how to get a sequence of buttons to flash. I ...

6. How can I make a non-Swing button in Java?    stackoverflow.com

I am creating a game in which I have a menu with multiple views for selecting game type, options, etc. using game state transitions. Each of the menus will be actively ...

7. Java button do the same thing, how do I change this?    stackoverflow.com

Alright, I have a simple java applet with two buttons and a screen. Both the buttons do the same thing. I want to change this. I can't find what it is ...

8. Need Java Help with Combining Multiple Classes in Gui    stackoverflow.com

I have prepared 2 classes which perform a function that I would like to wrap up in one nice easy to use GUI. Here is the first class:

import java.util.Scanner;
import java.text.*;

public class inputDecimal ...

9. How to set the Date Picker just below the button    stackoverflow.com

I want to open a date picker by clicking on button. But when I click on button, it will show a calendar in top left corner of the screen. ...





10. Implementing back/forward buttons in Swing    stackoverflow.com

I have a quick question. I'm getting a little bit of experience with Swing and the easiest way to do this was to draw up a reasonably big GUI. As part of ...

11. Execution trapped inside the button    stackoverflow.com

I have a method called inside a button that run almost an infinite loop. I can't access the other buttons while running this method. How I make to free the interface ...

12. Java Swing Help    stackoverflow.com

I'm trying to create a grid of JButtons, with index values to the left and right of the button grid. Here is my code, but I'm getting a NullPointerException. What is ...

13. why are my buttons not showing up?    stackoverflow.com

I am trying to create an array of buttons as a simulation of a seatingChart, but the buttons wont show up on the screen only the frame shows up. what am ...

14. List of buttons in swing    stackoverflow.com

I would like to implement a list of interactive buttons using Swing. It is something similar as on the picture (from NetBeans UI designer): enter image description here You can drag ...

15. JAVA GUI Button Question    stackoverflow.com

so I have some code that looks like this:

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.BoxLayout;
import javax.swing.JSeparator;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class IPGUI extends JFrame implements ActionListener 
{
    private ...

16. Stop watch button    stackoverflow.com

What to do to operate the button to stop and start the clock, while I want it when pressed to stop and continue the count with changing of it's label. Now I ...





17. How to programatically call a button that runs as an independent task?    stackoverflow.com

I have implemented Conway's Game of Life problem in Java swing. Everything is working fine. As you can see in the screenshot below, whenever the "Tick" button is clicked, ...

18. To quit window by button    coderanch.com

public void actionPerformed(ActionEvent e) { if e.getSource()==button // button i want to use to close frameName.setVisible( false ); // if your application has // multiple frames and you just want to close one... // You can also use frameName.hide(), or frameName.dispose() // instead of frameName.setVisible( false) like Paul has been // saying... }

19. Choice Button Problem    coderanch.com

How many items do you have in your Choice? If you replaced it with a List component you don't have to worry about the menu going off the edge of the screen. ( I think they have fixed this problem in newer versions of Java by making the menu a fixed size and adding a scrollbar if there are more items. ...

20. Awt Button    coderanch.com

21. How to chnage the angle of a button ?    coderanch.com

Man... this was a pretty fun class to make work... Here's your angled button and a fun little test class to show the full range of this buttons movement... import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.border.*; public class AngledButton extends JButton { protected double angle = 0D; public AngledButton() { this( null, null ); } public AngledButton( Action ...

22. Buttons on CardLayout    coderanch.com

hello all, it is the first time I am using CardLayout and I am definitly doing something wrong. my problem is that any CheckBoxes and RadioButtons on the cardlayout-panels don't act like they should. That is, when I click on them nothing happens. Only after changing the cards and coming back to the specific button again, it might be selected. Same ...

23. x,y of buttons ?    coderanch.com

Gets the location of this component in the form of a point specifying the component's top-left corner. The location will be relative to the parent's coordinate space. Due to the asynchronous nature of native event handling, this method can return outdated values (for instance, after several calls of setLocation() in rapid succession). For this reason, the recommended method of obtaining a ...

24. Button with choice    coderanch.com

Hi, in swing what is the name of a button that can also be a list. It is usually used in toolbar, such as the one in internet exlporer. You can chosse between a click on the button or a click on a little arrow that makes a menu appear. (example : the "back" button of I.E.) do you see what ...

25. How can i get specific button in JOptionaPne    coderanch.com

hi, I wrote a little test case. here is my conclusion: - providing JButtons as options argument to the showOptionDialog method does not work as expected: the buttons are displayed and if an initialValue is given, the appropriate button is focused, but the option pane does not return a value, and thus, not close. to use this solution you would have ...

26. Language on buttons    coderanch.com

27. how to gray out buttons    coderanch.com

28. Graphic for button in Free-Standing application    coderanch.com

Hi, I am writing a Free-Standing application using Java j2sdk1.4.1_04. The usual button that we create by just simply type the text on, can we place a picture/graphic instead of using text? Please advise the coding on how I can code it. I have been searching over the book and net and couldnt find any.

29. Placing a button anywhere    coderanch.com

I'm unaware of a "standard" XY-layout manager in Java, though in the past some IDE vendors have created custom layout managers that used a fixed X- and Y-coordinate placement (eg., Borland's JBuilder 8 has an XYLayout class). The GridBadLayout manager might be contorted to provide this, provided you put everything into the same grid and used GridBagConstraints to provide X- and ...

30. Some buttons do... Some buttons don't...    coderanch.com

Here is my class: SubChoicesPanel import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class extends JPanel implements ActionListener { int tally []=new int [100]; JLabel subChoiceLabels[]=new JLabel[100]; JButton plus[]=new JButton[100]; JButton minus[]=new JButton[100]; JLabel l[]=new JLabel[100]; static int colors[][]= { { 255,230,100 }, { 255,210,100 }, { 255,190,100 }, { 255,170,100 }, { 255,150,100 }, { 255,130,100 }, { 255,110,100 ...

32. defautl button?    coderanch.com

import java.awt.*; import javax.swing.*; import javax.swing.event.*; public class DefaultButtonTest { public static void main(String[] args) { final JInternalFrame iframe = new JInternalFrame("", true, true, true, true); final JButton button1 = new JButton("button 1"), button2 = new JButton("button 2"), button3 = new JButton("button 3"); iframe.addInternalFrameListener(new InternalFrameAdapter() { public void internalFrameActivated(InternalFrameEvent e) { iframe.requestFocus(true); iframe.getRootPane().setDefaultButton(button2); } }); JPanel panel = new JPanel(); panel.add(button1); ...

33. Button Problems    coderanch.com

The reason for the 1st 5 errors you listed are probably because these classes that your are trying to make new objects from don't exist. And then you try and use these classes in your code. You might need to check and see if your teacher has these or maybe these are what you are supposed to create for your assignment. ...

35. Problem with EDIT button.    coderanch.com

36. Buttons on Java...    coderanch.com

You guys..I'm stuck again....My Lays button and my popcorn button do not work when I click on them....it looks like I made them the same way..so what's wrong??? import javax.swing.*; import java.awt.*; import java.awt.event.*; public class VendingMachineDemo extends JFrame implements ActionListener { public static final int WIDTH = 500; public static final int HEIGHT = 200; private JTextField message; public VendingMachineDemo( ...

37. Releated Swing Button    coderanch.com

38. Bolded buttons, unbolding themselves..?    coderanch.com

HI I have a really strange problem and I don't know where to look in my code for it so hopefully someone out there can help me I have a GUI with some buttons on it - all of which have the text as bold. Its an odd problem which I haven't quite managed to track down to a certain action ...

39. creating button with dual purpose    coderanch.com

Hi I have created a button 'Start Search' and when you click on it, a Binary Search Tree is displayed. However, I would also like this button to then change to 'New Search' - I have done this by just changing its label text when the button is clicked. Now I want to set it up so that if 'New Search' ...

40. Adding Buttons in JDesktoPane    coderanch.com

41. pictures for buttons    coderanch.com

42. Dead buttons    coderanch.com

I recently had a problem adding a "reset" button to a GUI I've been modifying. You can see the original problem in this thread. As it hints in that thread, I'm now having problems with other buttons on the GUI. I've removed most of the "static" identifiers that the program was using and changed it so the program calls instances of ...

43. stetching buttons    coderanch.com

45. Swing Program with Buttons    coderanch.com

> The string at the very bottom, private String reverse(String inStr) > is just not outputting correctly. there is no 'reverse' code in the method, it returns what it gets from the text area memo3 = theText.getText(); theText.setText("hello"); //reverse the string then return it return memo3; but, at this stage it is irrelevant - the method reverse(..) is not called

46. Disappearing buttons    coderanch.com

48. Enabling buttons on rowselection    coderanch.com

49. How do I get my button to work?    coderanch.com

OK the code below is nasty I know. It's a hack of an example from Head First Java. I'm trying to diaply 3 text fields and a button. This I have managed, yes it looks nasty buy the cosmetics I can work on later. Only problem is I cant figure out how to get the button to work. What do I ...

50. button not working, please help    coderanch.com

Hi, i am developing a chat application using sockets.I have used two panels in a frame. My problem is that the button in panel isnt working, i have used the same action event for both the panels.. i am adding here the part of my code.. import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; public class Fpage extends Frame implements ActionListener ...

51. need to create a Navagation Button control using Annotation    coderanch.com

hi CR, when i click a button on a screen it should open up an another tabItem, i wanted to implement using annotation, but i am do not know anything about annotation, with out using annotation i have implemented it. presently i have a print menuItem in my file menu, when i click on the print it does not open up ...

52. paramString() method of Button class?    coderanch.com

53. swing buttons    coderanch.com

54. swing buttons    coderanch.com

55. Using Polygon/SVG for Buttons?    coderanch.com

56. swing buttons    coderanch.com

57. Buttons don't work    coderanch.com

I am taking a Java class currently and we are learning swing. I am creating a mortgage gui using swing. I have created a very nice looking gui but the buttons don't work. I have looked at 4 differenct books on how to create actionListeners etc. and it looks like they should work but they don't. I hope I have added ...

58. Buttons!!    coderanch.com

59. Button Renderer problem in Java swings    coderanch.com

60. How to make buttons active and non-active    coderanch.com

Hi, I don't know what words to use. But on a panel using cardlayout i have added many cards and. On the first card i have a text field and a password field i have already stored those username and password and when i press the ok button i enters the next card, till here its fine and works good. Now ...

61. Buttons...    coderanch.com

How can you say "If this button is clicked, and this button is clicked, and this button is clicked, Do this" The thing is They have to be clicked within a certain order. if (("X".equals (box1))&& ("X".equals (box2)) && ("X".equals (box3))) if (("X".equals (box1))&& ("X".equals (box2)) && ("X".equals (box3))) { Winner = new JLabel ("Player One is the Winner!!"); box1.setEnabled (true); ...

62. You know how macs make one button pulse?    coderanch.com

One way to make colors pulse is to create a simple sin-wave of color change. In other words take your starting color and your finishing color and interpolate the colors in between so they fall on a sin curve. This makes for a nice smooth transition of color. For instance: import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import ...

63. How to create close buttons    coderanch.com

I have created a very simple gui application: There is a Run Class that run the application an start the MainScreen class that calls the initialize method from the constructor creating a button called "aButton" when the user presses aButton, the MainScreen closes. So this is how i have implemented the aButton mouseClicked method: me.dispose(); "me" in this case is a ...

64. DoubleBuffering when there are buttons    coderanch.com

Hi. I have a problem. I am making Connect Four and just implemented DoubleBuffering to make it smooth when i repaint (as I may add animation later), and I have buttons that the user clicks on to drop tokens into the board. However, when I implemented DoubleBuffering, it paints over the buttons I have. They are there, but invisible or flicker ...

65. Doubt with buttons    coderanch.com

Hi, this is my first post and my english is bad, so I need learn english and Java,eheheheh!! How can I do to put my buttons in anywhere? Example: Bellow my code import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class MenuCli extends JFrame{ private JMenu lancamento,operacoes; private JMenuBar barmenu; private JMenuItem cliente,compromissos,sair; private JMenuItem consultar,alterar,excluir; public MenuCli(){ super("Agenda de ...

66. Back button not working    coderanch.com

import java.awt.*; import java.awt.event.*; import javax .swing.*; import java.io.*; import java.awt.event.ActionEvent; import java.util.StringTokenizer; public class FindPatient extends JFrame implements ActionListener { private JLabel Name,MRN,Address,Age,Admission,Wardname,Wardnumber,Blank1,Blank2,Blank3,Blank4,Blank5;// declares the labels,the blank labels are used for spaces in the layout private JTextField name,mrn,address,age,admission,wardname,wardnumber;//declares the text fields private JButton Search,Back;// declares the buttons public static void main(String args[])//main method { FindPatient app = new FindPatient(); } ...

67. Button.setBorder()    coderanch.com

I have a button. Currently there are no borders to it. I want to add a border to my button, but just on one side. Either Left or right. I was going through the api's and i found something called as setBorder(Border b). This function takes an Object of type Border. I searched through the api's but couldnt find way to ...

68. button for one-time usage    coderanch.com

69. Test for button obscured    coderanch.com

> What the simplest, most elegant way to test a button is not obscured ie the user could click on it ? don't know if this qualifies as elegant, but it works OK run program, click button, should be false scroll OK button into view, click check button, should now be true import java.awt.*; import javax.swing.*; import java.awt.event.*; class Testing { ...

70. manage buttons with request to and from server    coderanch.com

my application have a frame with seven buttons i.e login,ready,notready,call,releasecall,logout,cancel at client side. when i click on button a request is sent to server. client process request and send response back to client. on the basis of response received read write buttons are enabled. i don't know how to code this in Swing. can anybody please tell me in details how ...

71. Form Functions...Need a button!    coderanch.com

72. Need a little bit of help stacking buttons    coderanch.com

Is there a classmate that attend the class you missed that might be able to provide you with notes? Or at least can give you a better general idea of what your teacher discussed? Can't you contact the teacher? Most teacher's today do provide their e-mail addresses. (Or is this not a college class?) If we at least had a good ...

73. how to add button to this?    coderanch.com

how to add a button at the bottom to this applet? and if i have another class which is the main, what will i add to call this class? i try to instantiate it in main like Animation an = new Animation(); an.start(); // i call the method start but it did not work. import java.awt.*; import java.applet.*; public class Animation ...

74. simple piano to play using buttons    coderanch.com

i am in need of a simple source code for a piano having 8 buttons . Each button should play each individual musical note on click. i've searched for such code on google but didn't find anything exact,most of the codes were self playing which doesn't require user input. please paste the code in reply if anybody have it and also ...

75. Get button created by ActionContributionItem    coderanch.com

The reason I ask is because I would like to create a JFace action with ImageDescriptor, but I only want that image to appear on the button, not in the menu. Right now, I'm having to create 2 instances of my action, I pass one to the menu, and the other one gets the ImageDescriptor and gets passed to the button. ...

76. I want to use an add screen to add infromation to a hashmap, but cant get the add button to work    coderanch.com

I am working with a hashmap and have passed the table from the menu (where the haspmap is read from a datafile) to the Add screen (I can enter information into the hashmap frpom the consol) but whenever I try to read from the screen itself using an add button I cannot get the button to map to the hashmap? map.put(RegNo,new ...

77. getting a problem ,can't see the button    coderanch.com

hi , i was testing out card layout. What i want in my application is three panels At first i want the frame to be Divided into two panels and then add buttons on it . This is where the problem is coming. The button is not visible on the panel . It is visible when i remove the second panel ...

78. adding a button    coderanch.com

i've made a very small code and now i want to add a button on top of it but i don't know how . Can somebody help ? Maybe i am missing an important concept regarding what to add where . So please point me to the right direction import javax.swing.*; import java.awt.*; import java.awt.geom.*; public class Draw { public static ...

79. GUI Buttons Help    coderanch.com

The below GUI code is a simple scorekeeping program. The problem is the buttons. They're not working like they should. You'll understand when you run it. I used the NetBeans GUI maker for this; I'm not an experienced programmer. I've only had one year of Java in school. Anyways, it would be nice if you could change it / tell me ...

80. Mac-savvy Help button    coderanch.com

Here's a bit of code I'm using to get a native-style "Help" in Mac OS X while maintaining compatibility with other Look-and-Feels. A round purple button with a "?" icon appears. Setting the Client Property "JButton.buttonType" to "help" causes the Mac-savvy button to appear, at least in later versions of Java and Mac OS X. The next step is to suppress ...

81. Blanking out a button if they do not have enough funds in their bank.    coderanch.com

Hey guys, im new to java and am wanting to disable a button say "20" if they do not have enough funds in their bank. I have had a shot at it but i keep getting "operator cannot be applied to java.lang.string,double. I'm pretty sure im missing something simple here.. =( public class ATMWithdraw extends JPanel implements ActionListener { // Declare ...

82. how to use jfile chooser button ??    coderanch.com

i have a browse button to get input file from user and when this browse button clicked it should select d file needed, how to apply this with file chooser ??? i have doubt that to apply like method1 or method2: method 1: input file [-----------------] [browse] a open window opens you to select method 2: directly having a file chooser ...

83. Functionality of Buttons    java-forums.org

Functionality of Buttons I am hoping someone can help me with this. I have to add an "Add", "Delete", "Modify", "Save", and "Search" buttons to the below inventory program. I have been able to add all of these buttons to the program. In addition, I have been able to get the "Add" button to function. However, I am having ...

84. how to build reuasble swing buttons    java-forums.org

85. how to insert button in jfreechart    java-forums.org

86. button coordinates    java-forums.org

a GUI application that presents a game based on a 4 by 4 matrix of buttons.One of the buttons (selected at random) "hides" the prize. A status bar at the top of the window shows the number of guesses. When the prize button is pressed, the status bar shows "You got it in x attempts!". While pressing buttons, the distance to ...

87. generating 26 buttons    java-forums.org

import java.awt.Button; import java.awt.event.ActionListener; import javax.swing.*; public class HangmanPanel extends JFrame { //this is the used letter array private boolean usd[] = new boolean[26]; private String guessme; private int numguesses=0; private boolean finished = false; private boolean won = false; private Button a[][COLOR="Red"];[/COLOR] public void init() { int i; StringBuffer buffer; a = new Button[26]; new ActionListener() { public void actionPerformed ...

88. Button Glitch    java-forums.org

Hi. I'm fairly new to java, so my code may seem "immature", but I am hoping to get advice on a problem I am having. Java Code: package merp; import javax.swing.*; import java.awt.event.*; public class TicTacToe { int nSize = 100, nTurn = 0, nSquares[][] = new int[3][3], Player1 = 0, Player2 = 0, nTurnCount = 0, nDraw = 0; JButton ...

89. Level Restart Button    java-forums.org

I've had good success following tutorials online but now i have come across a stumbling block. My project is a child's mathematical game. I want the user to be able to click "restart level" and the Frame reset all components and variables. I've come across repaint(); / revalidate(); and similar methods but i think the terminology escapes me. The code would ...

91. How to make buttons vertical    java-forums.org

92. override the close button    java-forums.org

93. calling buttons from diffeent class    java-forums.org

Java Code: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import java.awt.*; public class MyFrame extends JFrame { public MyFrame() { setTitle("My graphic frame"); setSize(1000, 800); // Creates a menubar for a JFrame JMenuBar menuBar = new JMenuBar(); // Add the menubar to the frame setJMenuBar(menuBar); // Define and add two drop down menu to the menubar JMenu fileMenu = new JMenu("File"); JMenu ...

94. Glow button    java-forums.org

Hi, I am trying to make a program in which when i put my cursor over a JButton, it will glow and when i removed the cursor, it will stop glowing. I know it can be done by setRollOver() method but i am not able to achieve that. I made a program in which when cursor comes over JButton it image ...

95. Using a button to change the interface    java-forums.org

The idea is there are 5 buttons on the top of the screen. Every time you press one it removes the old menu and produces a new one. To me, my code looks fine. The problem is when i click on "Add CD" nothing happens, but then if i manually resize the window (moving my mouse to the edge of the ...

96. Using my own-designed buttons & textboxes    java-forums.org

97. How Can I space out buttons?    java-forums.org

98. button formalize    java-forums.org

hi .,, use some layout patterns always ., if u want ur application in form like manner ., u have to use gridbaglayout ., study about gridbaglayout ., if cant able to get ., how it works ., reply me ., dont use lazy like words in forum ., ur problem is not so intresting topic to discuss ., so no ...

99. How do I make my buttons work in the GUI of this code?    java-forums.org

Hi, so i have a background image and added buttons (with icons on them) on top of the background. Now, I'm trying to figure out how I can make these buttons do something when they are clicked on. Here's the code: Java Code: import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; import javax.swing.JFrame.*; import java.awt.event.*; import java.awt.image.*; import java.awt.geom.*; ...

100. implementing a button instead.    java-forums.org

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class OneOption implements ActionListener { JTextField entryField; JLabel label; public void actionPerformed(ActionEvent e) { String text = entryField.getText(); label.setText(text); } private JPanel getContent() { JPanel panel = new JPanel(new BorderLayout()); panel.add(getLabel(), "North"); panel.add(getEntry()); panel.add(getButton(), "South"); return panel; } private JLabel getLabel() { label = new JLabel(); label.setPreferredSize(new Dimension(100,30)); label.setHorizontalAlignment(JLabel.CENTER); return label; } private JPanel ...