jbutton

Java: How to reference GUI components from an AbstractAction object?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-12 08:08:31
问题 It is often necessary to change the behaviour of other GUI objects depending on the state of another GUI object. E.g. when a button is pressed, a label shall change its name. However, when I use an AbstractAction object like JButton myButton = new JButton(myButtonAction); I need a reference to the GUI objects in the object that inherits from AbstractAction. Should I just create the AbstractAction objects in the GUI and then pass all the necessary GUI references to the AbstractAction objects

How to Play .wav File with JButton?

梦想与她 提交于 2020-01-11 13:59:11
问题 So recently, I have been trying to make my own Mario game (for myself, possibly to show my other friends). Games include buttons. When I click on a button in other games, it plays a sound. I would love to add that feature to my game. The problem is, it doesn't play. My source code is: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip;

getRootPane() default button - Is this a bug?

烈酒焚心 提交于 2020-01-11 13:24:23
问题 I have made an SSCCE. Please note that it must be Windows Look&Feel. import java.awt.*; import javax.swing.*; public class DefaultButtonBug { private static final String LAF_WINDOWS = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; public static void main(String[] args) { try { UIManager.setLookAndFeel(LAF_WINDOWS); } catch (Exception ex) { System.out.println("Setting the L&F failed so I cannot reproduce the bug."); System.exit(1); } EventQueue.invokeLater(new Runnable() { @Override

Packaging a program containing images

一曲冷凌霜 提交于 2020-01-11 10:26:26
问题 I'm having massive issues packaging my java program which contains images into a jar for conversion into and executable file. The images have been used in the background of the program and buttons. Please see the diagram below which shows the program I desire to convert to a jar. IMAGE As you see above the program runs OK. I created the same program with no custom background and custom buttons containing no images and I successfully packaged it into a jar and subsequently into an .exe file.

Unable to add two buttons in a single cell in a JTable

若如初见. 提交于 2020-01-11 05:51:08
问题 I am trying to make a dynamic table that fetches data from a database and adds those data in separate rows.. I want to add an extra cell with each row(dynamically) that contains two buttons...and on clicking those buttons some event should occur only on the respective row .. (P.S: I have managed to fetch data from the database and add it to the table though..) Here is an example: _____________________________________________________________ ID | Name | Application for leave | Accept/Reject |

How to create a custom JButton in java with an image base?

扶醉桌前 提交于 2020-01-11 05:13:09
问题 I recently read this thread (Creating a custom button in Java) on creating custom buttons in java by extending the JButton class, however all the solutions on this thread use graphics drawn in java. I wanted to have my button based on a button image I had drawn in photoshop. So I tried to apply what I read in that thread with this result: import javax.swing.*; import java.awt.*; public class nextButton extends JButton { @Override protected void paintComponent(Graphics g) { Image image = new

Design Button in Java (like in CSS)

≯℡__Kan透↙ 提交于 2020-01-11 04:09:04
问题 For my project, I need to create customizable buttons. Except that I have a problem and I do not know how to solve it. I have a background image for my button and I would like it to be extensible in X and Y according to the text there will be over without loss of quality. Do you have any ideas? 回答1: Swing has a pluggable Look&Feel which allows to alter the appearance of its widgets by means of a ComponentUI (in this case: a ButtonUI ). Example for your buttons: class StyledButtonUI extends

Making a JButton clickable inside a JTable

╄→гoц情女王★ 提交于 2020-01-09 07:20:28
问题 Here is the screenshot of what I want to do : What's happening there is the JButton shows correctly but nothing happens when I click on it. After some search, I've found that the Object returned by table.getValueAt() is a String instead of a JButton... Here is the code : tblResult = new JTable(data,cols) { public TableCellRenderer getCellRenderer( int row, int column ) { return new ClientsTableRenderer(); } }; I use this for populating at run-time the JTable : ( tblResult is now Clients

when i click JButton i want that game should start

心不动则不痛 提交于 2020-01-08 06:25:14
问题 I am working on a snake game project. I have three java files named: Engine.java GameBoard.java Snake.java I have added two JFrames in this project. In the first frame are three buttons: play rules exit When we click to rules button it opens rules jframe (it's working). When we click play button it should run the snake game. Please suggest me what should i do when i click play button to actually starts the game. This is the code i copied in play button actionPerformed method: JFrame frame =

Press on button equals print what ever is on JTextField on the label

大城市里の小女人 提交于 2020-01-07 09:35:10
问题 I want to make my JButton called enter function as enter for my JTextField . So like if I wear to press on the enter button it would put what I wrote down in JTextField in the the JLabel . Here's my code: package Main_Config; import java.awt.*; import javax.swing.*; import javax.swing.border.*; import java.awt.event.*; public class SET_UP extends JFrame { private JPanel contentPane; private JTextField textField; private JLabel consol; public static Dimension size = new Dimension(800, 700); /*