jbutton

Action Listener for JButton isn't working

巧了我就是萌 提交于 2020-01-07 03:38:39
问题 I'm trying to learn java by myself, and am looking to make a secure text editor that you have to log into to access the text. However, the action listener isn't working for any of the buttons, and i can't figure out what's wrong. Please note I've made two buttons only because the first didn't work. My code is below: public class storage extends JFrame{ private JTextField text1; public JTextArea storearea; public JButton newsave; public JButton save; public storage(UserProfile person) { /

Pass JButton to Utility class. Acceptable?

馋奶兔 提交于 2020-01-06 20:01:24
问题 I have a JFrame that does things. I have a JButton hidden from view in that JFrame. In a SwingWorker i have a utility Class such as checkNDownloadFile of which I pass a JButton to it. So it can make it visible/usable when the process completes. My question is, is this acceptable. I dont know of any other method to do this effect. (Keep in mind the checkNDownloadFile class is all static. Its only needed/ran once.) Sudo Code -----------------------------------------------------------------

Java - How to force buttons to bottom of panel after others have been removed?

这一生的挚爱 提交于 2020-01-06 19:41:26
问题 I'm making a very simple game in Java where when you press a button on your keyboard, the corresponding button is removed, however I want the buttons to all be pushed to the bottom accordingly when one is removed. I'm not sure where I should do this in the code or what method to use. Is there a way to sort of pack the frame so that everything is anchored to the bottom? Here is a picture of the program when it is ran: And when I press the 3rd button, I want the blocks above it to fall down on

I don't want to change color of JButton when pressed

。_饼干妹妹 提交于 2020-01-06 15:33:05
问题 Color newColor = new Color(197,222,90); JButton newButton; newButton = new JButton(icon); newButton.setBacgroundColor(newColor); When it is pressed it changes color. How can i keep it from changing color. I have multiple buttons, so if there is solution in one or two rows pls help me, and keep in mind that I'm beginner, writing some huge classes wont help me, because i have multiple buttons with different name to be affected with this. EDIT: Solution in one line is: UIManager.put("Button

I don't want to change color of JButton when pressed

耗尽温柔 提交于 2020-01-06 15:32:52
问题 Color newColor = new Color(197,222,90); JButton newButton; newButton = new JButton(icon); newButton.setBacgroundColor(newColor); When it is pressed it changes color. How can i keep it from changing color. I have multiple buttons, so if there is solution in one or two rows pls help me, and keep in mind that I'm beginner, writing some huge classes wont help me, because i have multiple buttons with different name to be affected with this. EDIT: Solution in one line is: UIManager.put("Button

Java Determine which textfield has Focus

天涯浪子 提交于 2020-01-06 15:30:31
问题 I have created buttons 1-9 as well as 4 text fields. I am trying to allow the user to click on any number 1-9 to input into each text field. However, I cannot determine which field the user is clicked on. Currently the 1-9 buttons only input text to the amt text field. How can I check which field is clicked and enter input into there? New Question public void actionPerformed(ActionEvent e) { String iamt, ii, iterm,ipay; iamt = amt.getText(); ii = interest.getText(); iterm = term.getText();

How to move 3 buttons inside a window

我的梦境 提交于 2020-01-06 07:26:14
问题 In the below code I am attempting to move the three buttons to the left when you click the left button. When I click it; nothing happens currently. Can anyone explain to me what I am doing wrong here? Also, for some reason it has stopped compiling correctly and I am unsure why but I BELIEVE it is because of a mistake in my code while attempting to get the buttons to move to the left when you click the button. I do NOT want the window to move. Just the buttons within the window. Does any one

Adding a child component to a JButton

北战南征 提交于 2020-01-05 13:24:11
问题 Is it possible to place a child component inside a JButton and make it transparent to a subset of mouse events so that: The child component receives MouseMotionEvent s (so it can respond by modifying a displayed image) Clicking still depresses the JButton "behind" the child component If you add the child component to the button but make no other changes, clicking in the area occupied by the child does not activate the button. I know this can be achieved by creating a new class that extends

Java JButton actionPerformed freezing

孤人 提交于 2020-01-05 10:11:34
问题 I've been fooling around with Java and I was trying to make a program that starts to ping an address and printing out the "ms". I have a JButton: JButton start = new JButton("START"); start.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ try { doCommand(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); And the doCommand() method looks like this: public static void doCommand() throws IOException{ String s = null;

Java - How to fill a Windows L&F button with color instead of just the border?

元气小坏坏 提交于 2020-01-05 08:40:41
问题 I'm doing a few GUI tests with Java on Windows 7. I would like to use the Windows Look & Feel because Java's default "Metal" UI is really ugly IMO. When I set the background color of a button, it just colors the border around the button rather than fill its whole background. public class GUITest { public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} // I know, not a good idea, but it's just a test JFrame