jbutton

is there a way to set a jbutton on top of a jbutton?

旧街凉风 提交于 2019-12-25 05:00:51
问题 I am wondering about this since we are making a game in Swing and we made our map tiles into jButtons instead of jPanels for whatever reason. Now we want to put units on top of them so the map background is still shown when the unit is on top of them. Anyone know if this is possible? 回答1: OK, so I am not sure this is really what you are looking for and how your application is currently set up, but this is an example to have JButtons on top of each other (if this is not what you are looking

how to properly set size of JButton with image?

青春壹個敷衍的年華 提交于 2019-12-25 04:17:12
问题 This is what I have now: This is what I want the image to look like: I have two java files, one extends JFrame and part with Jpanel looks basically ShinyButtons panel = new ShinyButtons(); panel.setLocation(10, 10); getContentPane().add(panel); another one extends JPanel with JButtons import javax.swing.*; public class ShinyButtons extends JPanel{ public static byte RED = 0; public static byte ORANGE = 1; public static byte YELLOW = 2; public static byte GREEN = 3; public static byte BLUE = 4

how to properly set size of JButton with image?

巧了我就是萌 提交于 2019-12-25 04:17:07
问题 This is what I have now: This is what I want the image to look like: I have two java files, one extends JFrame and part with Jpanel looks basically ShinyButtons panel = new ShinyButtons(); panel.setLocation(10, 10); getContentPane().add(panel); another one extends JPanel with JButtons import javax.swing.*; public class ShinyButtons extends JPanel{ public static byte RED = 0; public static byte ORANGE = 1; public static byte YELLOW = 2; public static byte GREEN = 3; public static byte BLUE = 4

How to change the color of an individual ellipse when clicking a jButton?

社会主义新天地 提交于 2019-12-25 03:47:58
问题 I want to be able to click the JButton and change the next individual ellipse I make to its respective color, Red or Black, from its default Blue. So far I'm able to change the color of all the ellipses I have made. public class MainClient { private JFrame frame; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { MainClient window = new MainClient(); window.frame.setVisible(true); } catch (Exception e) {

How to change Background color of a JButton from a derived class in Java Swing

旧时模样 提交于 2019-12-25 03:39:14
问题 I have a base class mainframe and i have keeping the JButton as final static Which its BGcolor going to be changed by a extended class of mainframe namely dataframe. Initially i need to set the BGColor of the JButton to red. Then I need to change it to some other colors from the dataframe. I can able to set the BGColor from the mainframe but not from the dataframe(extended class). I've used mainframe.Button_name.setBackground(color.yellow); but still its not changing `enter code here` public

Seems like JPanel background isn't read in FocusListener

流过昼夜 提交于 2019-12-25 03:32:45
问题 This problem appeared after my last question here. I want to set each button focused and lost focus background to background color which is below main menu (ContentPane which is JPanel), so buttons look like tabs. It couuld be different in different environments, so it is dynamic, so I can't set it manually. Now, If I log ContentPane background it says 238, 238, 238. If I log it inside FocusListener - it also states 238, 238, 238. If I directly set button's background to ContentPane

How to Position a JLabel in the specified Layout?

百般思念 提交于 2019-12-25 03:18:19
问题 I am trying to position my Labels and Button on screen. I found an answer here to set label's Position using: label3.setHorizontalAlignment(SwingConstants.CENTER); label3.setVerticalAlignment(SwingConstants.CENTER); but there has been no effect in my code. Also, on changing my layout from Flow Layout to Border Layout, only one Jbutton [CLEAR] appears on the Screen. Can anyone help me rectify this? public class Corrected1 extends JFrame { public JTextField tf1; public JTextField tf2; public

Java Action Listener Issues

亡梦爱人 提交于 2019-12-25 02:35:10
问题 I have a program that animates a ball in a Jpanel. I have two buttons Stop and Go. Stop stops the ball moving and go is meant for the ball to move around. In my ball class I have a boolean variable that if it is true the ball moves and if it is false the ball doesn't move. So I thought in my main class when I create the frame and put the ball class in the panel I could use the buttons to change the variable to false or true depending on the button press. public class BallTask extends JPanel

JButton is drawing behind an image

拈花ヽ惹草 提交于 2019-12-25 02:19:27
问题 I am making a starting screen, and it's working out pretty fine, got a background image when it starts, now I am trying to draw a JButton on the startmenu, which is a JFrame. But when I run my program, the button appears behind the background picture. If I hover above the area where the button is placed, it's flickering, and when I click it that happens too. Is there any way to draw the Button INFRONT of the background? I made the button as last in the code. My code to draw the background and

Unlock JButton as fields have text

百般思念 提交于 2019-12-24 22:58:13
问题 As the topic suggests I want to unlock(setEnabled(true)) my JButton register when the other fields have any text but I don't know what type of listener is this. I upload an image for clearer understanding. http://postimg.org/image/ab8alz44d/ 回答1: add a document listener for each text field. void init() { //construct text fields ... // add listeners textField1.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { checkUnlock(); } public void