jbutton

How to put a JButton inside a JComboBox

杀马特。学长 韩版系。学妹 提交于 2019-12-23 20:09:38
问题 I would like to put a JButton inside a JComboBox. This button lets users browse for files. The file the user selects gets added to the JComboBox list. How do I do this? Do I use some kind of a Renderer? Thank you. EDIT: After reading more about ListCellRenderer I tried the following code: JComboBox comboBox = new JComboBox(new String[]{"", "Item1", "Item2"}); ComboBoxRenderer renderer = new ComboBoxRenderer(); comboBox.setRenderer(renderer); class ComboBoxRenderer implements ListCellRenderer

Action listener for JButton array

吃可爱长大的小学妹 提交于 2019-12-23 19:31:29
问题 Let's say I have a program with 2D array of buttons, and when you click one of them it turns red. I didn't want to declare every single button seperately so I just created JButton[][] array for them. The problem is that I don't know how to use action listener on any of the buttons in the array so it would change the color of this particular button, and none of related questions is relevant to this. I tried to use "for" but it doesn't help: package appli; import javax.swing.*; import java.awt.

Is it possible to create a fade in effect for JButton using Timer?

点点圈 提交于 2019-12-23 19:04:03
问题 I want to put some effects on my program buttons. When I press the button ,the button should fade in. Using a timer to change the value of Opaque in new Color() is one of the way, but can it applied to JButton as well? Because the JButton has border. So, I want to ask that is it possible to create a fade in effect for JButton using a Timer ? If yes, can I ask for an example? 回答1: Is it possible to create a fade in effect for JButton using Timer? I think that no issue with that, If yes, can I

implementing next and previous buttons using a LinkedList

喜欢而已 提交于 2019-12-23 18:28:32
问题 This might be a stupid question, but I'm having trouble thinking this through. I wrote a method that uses a LinkedList to move through loaded MIDI instruments. I want to make a next and a previous button so that every time you click the button you traverse through the LinkedList. If I hardcode itr.next(); or itr.previous(); multiple times I can traverse through the LinkedList public void setInsturment(Synthesizer start,MidiChannel currentChannel[]) { try { start.open(); Soundbank bank = start

JButton & Action & KeyBinding

时光怂恿深爱的人放手 提交于 2019-12-23 17:23:28
问题 I have created a JButton class that recieving Action, the JButton class includes keystrokes & mouse listener so i can use the same class in multiple frames as needed. My problems is that: JButton not getting the focus when pressing the key, but it doing the action. i need to make a new background or something that tell the user that the button did the action. Any ideas?? Here is my code: import java.awt.Color; import java.awt.Dimension; import java.awt.Insets; import java.awt.event.KeyEvent;

Get button name from ActionListener?

北城余情 提交于 2019-12-23 09:38:17
问题 I have scoured the internet but can't find an answer to this : I'm using a for loop to create 36 buttons called a1, a2, etc. and assigning each of them a unique Action Command at the same time. Later on I wanted to get the name of the button from the actionPerformed(ActionEvent e) method. I could get the ActionCommand easy enough, but I need the name of the button as well. Any help much appreciated! Edit: Here is the code I'm using: String letters[] = {"0", "a", "b", "c", "d", "e", "f"};

checking if a jbutton is clicked in another java file

六月ゝ 毕业季﹏ 提交于 2019-12-23 06:11:05
问题 good day everyone. I have many java files in a project in netbeans. One file is named mainFile while some are addSale, addAttendance. In my mainFile.java, I created an actionPerformed method to check if a button is clicked. But the buttons that I want to checked if clicked is on the other java files. I've added this code in my mainFile.java AddSales addSaleButton; Login logButton; public void actionPerformed(ActionEvent ae){ if (ae.getSource() == addSaleButton.getButton()){ System.out.print(

If-else condition within a JButton ActionEvent

拜拜、爱过 提交于 2019-12-23 05:29:04
问题 I've just uploaded my progress into the program. Please have a look and see what is lacking in it. Also, please ignore the lame joke from the strings in it while you're at it. It can be downloaded from this link: http://www.mediafire.com/?n0sp8v22egfsx7t Note that I used NetBeans to easily make the program. Edited: How do I stop the ActionEvent method of a JButton from re-iterating the reading of the first layer of the nested if-else condition once the innermost line or last line of codes is

Java keeps adding buttons! - JFrames - [closed]

人走茶凉 提交于 2019-12-23 05:25:30
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . Alright, so, I am trying to make a game using a JFrame that, when you click a button, adds money, and show update some text(a JLabel ). You see, it should just update the Windows.Money variable and display ONLY the new variable on the screen, but, it adds more buttons. Please note: The money part

Multiple screen java applet has buttons that don't work

扶醉桌前 提交于 2019-12-23 05:23:09
问题 I'm making a program that has 2 screens, a title and a game screen. If the user clicks "Play", they can proceed to the next screen. However, on the next screen if the user tries to press the button "Keep Going", nothing happens. I want to know why this is and if anyone can fix it. Thanks, and here is my code: import java.applet.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class ZombieDice extends Applet implements ActionListener { Panel p_card; Panel card1,