jbutton

How to make String value to call specific existed JButton variable name in java?

匆匆过客 提交于 2019-12-22 08:52:21
问题 So, I know there is this: int number = Integer.parseInt("5"); String numtxt = Integer.toString(12); double number = Double.parseDouble("4.5"); String numbertxt = Double.toString(8.2); String letter = Character.toString('B'); char letter = "stringText".charAt(0); so on... but what I don't know how to make String value to call existed JButton variable name dynamically; is it even possible? Let's say, I have 4 JButton called btn1, btn2, btn3 and btnFillNumber; I create a String called buttonName

Animated ImageIcon as Button

旧巷老猫 提交于 2019-12-22 08:48:50
问题 I have an imageIcon as Button, now i would to animate it when you rollover. I tried to use a animated gif (without loop) on setRolloverIcon(Icon). But when i hover again on the button the gif is not playing again. When i use a looped gif then it plays it from a random frame. I tried using paintComponent to draw a Shape or an image as Button, which works fine, but even when i use setPreferredSize() or setSize() or setMaximumSize() the Button uses its default size, as you can see in the picture

Browsing JButtons with Arrow Keys

百般思念 提交于 2019-12-22 08:07:16
问题 I've made a JButton array, which represent cards, there are 16 of them, 4 by 4. How can I browse among the JButton with the arrows on keyboard instead of the mouse, and how can I "click" on JButton by pressing ENTER instead of mouseclicking? Maybe there is another way of doing this instead of using JButton s? Best regards! 回答1: I have created a solution that will allow you to navigate buttons with the arrow keys and activate them with space and enter. Below is all of the code. No comments are

Java isRollover() method does not produce an event in my swing application

风流意气都作罢 提交于 2019-12-22 06:29:59
问题 I am reading a great book called Swing: A Beginner's guide. There is this code in the book that creates a button and a label that alerts on button's state change events : //Demonstrate a change listener and the button model package swingexample2_6; import java.awt.*; import javax.swing.*; import javax.swing.event.*; public class ChangeDemo { JButton jbtn; JLabel jlab; public ChangeDemo() { //Create a new JFrame container JFrame jfrm = new JFrame("Button Change Events"); //Specify FlowLayout

“Un-rollover” a JButton when a JOptionPane is displayed

十年热恋 提交于 2019-12-22 04:06:10
问题 I have a situation where I need to display a JOptionPane after clicking on a JButton. The JButton has a default icon, and a rollover icon (which displays when, well, the mouse rolls-over the button). However, once the button is clicked and a JOptionPane appears, the rollover icon does not change back to the original, and continues to remain so until the user brings the mouse back to the JButton's frame after selecting an appropriate JOptionPane choice. How would I "un-rollover" the JButton

Blinking Button for Simon Says

只愿长相守 提交于 2019-12-22 00:31:37
问题 I'm making a Simon says program and I need the buttons to flash when the random pattern is generated so the user knows what to enter. My problem is that I cannot get my buttons(JButtons that are images) to blink, my logic is having two buttons on top of each other, one visible and on not and then switching the buttons visibility, waiting a second and then changing it back. I've tried to use Thread.sleep(), wait(), and even busy loops to wait but none have worked. I've been told a swing timer

How to make JButton with transparent background and regular text?

故事扮演 提交于 2019-12-21 21:09:10
问题 Is there a way to make a JButton which has a transparent fill(30% transparent) and a text which is not transparent? For now I discovered the following options: make both the button and the text transparent. make both of them not transparent. is there an option in between? 回答1: Here is one possible implementation using JButton#setIcon(Icon_30%_transparent) : import java.awt.*; import java.awt.geom.*; import java.awt.image.*; import javax.swing.*; public final class TranslucentButtonIconTest {

Place components at arbitrary (x,y) coordinates

蓝咒 提交于 2019-12-21 09:06:47
问题 I want to place some buttons in a JPanel at random positions (x,y), and these layout classes are annoying. Is this even possible in Swing? 回答1: You can set the coordinates if you use a null layout: panel.setLayout(null); Button b = new Button(....); panel.add(b); b.setSize(width, height); b.setLocation(x,y); But it is strongly recommended to use layouts. Layout classes are not "annoying", they are your friend if you understand them properly. I propose reading a tutorial about GridBagLayout,

smooth rounded corners in swing

ε祈祈猫儿з 提交于 2019-12-21 06:58:20
问题 I want to make smooth rounded corners for my swing application, but I can't get my desired result... here's the screenshots: 1. setShape() for JFrame : 2.overriding paintComponent() method for JPanel instead of using setShape() : 3. setBackground(new Color(0, 0, 0, 0)) for JFrame : well, but there's a problem with text quality: before step 3 : after step 3 : guys I'm confused, I've searched many times but nothing helped me... what should I do? please help me here's the full code : public

Making JButtons overlap

六月ゝ 毕业季﹏ 提交于 2019-12-21 05:25:13
问题 I'm creating a virtual piano type program in Java Swing. My area for the piano keys right now is a JPanel with a horizontal BoxLayout containing white JButtons as white keys. I want to add black keys as well, and have them overlap the white keys. There are two different approaches I've tried. One is using the OverlayLayout. Unfortunately there isn't much documentation online for the OverlayLayout manager, and it's not available in the NetBeans GUI builder. I don't have a clue how to make it