jbutton

How to move JButtons and JLabels position in a JPanel, JFrame

瘦欲@ 提交于 2019-12-23 03:38:15
问题 I am creating a simple lottery as a practice, I am a beginner of Java. I have achieved almost everything that I want apart from one thing: Moving the different texts and buttons to the position that I'd like them to be. Here is a picture edited in Photoshop describing how I would like it to be: The Lottery currently looks like this after you press the Play button: (As you can see the buttons get shifted to the right in order to make space for the text that is squished in to the left of the

Adding multiple instances of a JButton to JFrame in grid

青春壹個敷衍的年華 提交于 2019-12-23 03:37:17
问题 The code below is supposed to create and object instance for a specific type (say color) JButton I want to represent in a grid. When I iterate through the for-loop to add the buttons to the jframe it adds nothing. But if I add a single instance variable it will add that. Anybody have an idea? public class Grid { protected JButton [][] board; private JButton player; private JButton openCell; private JButton wall; private JButton closedCell; public Grid(String [] args) { // args unused //

Connect/link buttons graphically together?

为君一笑 提交于 2019-12-23 02:49:10
问题 Simple question, is there a way to create a sort of "button group" (no, not this), where two or more buttons are connected together. If you look at JTabbedPanes, for example, on a mac system you get this: This is exactly what I'd like to have with a set of buttons. Pushing two or more buttons together, like seen in this post, does not work as the border layouts conflict and is also uneven: I have been searching around for a while on anything like this but I haven't been able to find anything.

Swing: Enabling Buttons With Delay

冷暖自知 提交于 2019-12-22 20:46:32
问题 private void OptionsActionPerformed(java.awt.event.ActionEvent evt) { // After clicking on button X, I want 4 other buttons to show up // in a sequential order ButtonTrue(); } public void ButtonTrue() { Audio_Options.setVisible(true); letsSleep(); Control_Options.setVisible(true); letsSleep(); Display_Options.setVisible(true); letsSleep(); Network_Options.setVisible(true); } public void letsSleep() { try { Thread.sleep(10000); } catch (InterruptedException ex) { Logger.getLogger(MainMenu

Swing: Enabling Buttons With Delay

房东的猫 提交于 2019-12-22 20:46:10
问题 private void OptionsActionPerformed(java.awt.event.ActionEvent evt) { // After clicking on button X, I want 4 other buttons to show up // in a sequential order ButtonTrue(); } public void ButtonTrue() { Audio_Options.setVisible(true); letsSleep(); Control_Options.setVisible(true); letsSleep(); Display_Options.setVisible(true); letsSleep(); Network_Options.setVisible(true); } public void letsSleep() { try { Thread.sleep(10000); } catch (InterruptedException ex) { Logger.getLogger(MainMenu

JButton with padding between its border and the button itself

牧云@^-^@ 提交于 2019-12-22 13:05:13
问题 I've a JButton that has its background green-colored and its border as a LineBorder. I would like to insert a space between the button and the border, a kind of padding. I've tried with setMargin(new Insets(x,y,t,z)) but it seems not working. This is my piece of code. JButton JBtn=new JButton("sdfd"); JBtn.setBorder(BorderFactory.createLineBorder(Color.CYAN,5)); JBtn.setBackground(Color.GREEN); JBtn.setMargin(new Insets(5,5,10,10)); Any advice? 回答1: The borders are part of the button and

JButton Positioning Issues

风格不统一 提交于 2019-12-22 12:21:35
问题 Okay, I have a Jpanel which is shown as white in the below image using an overlay layout. It holds a ScrollPane holding an image ("No Image Available") and a JButton ("Comment"). I want to position this button in the bottom right hand corner of the JPanel. I have tried multiple layout approaches and I cant seem to get it to work. At most the button moves about 3/4 of the way South-East and I have no idea why. Any help is greatly appreciated.. 回答1: There are a lot of possible solutions using

JButton Positioning Issues

喜你入骨 提交于 2019-12-22 12:20:08
问题 Okay, I have a Jpanel which is shown as white in the below image using an overlay layout. It holds a ScrollPane holding an image ("No Image Available") and a JButton ("Comment"). I want to position this button in the bottom right hand corner of the JPanel. I have tried multiple layout approaches and I cant seem to get it to work. At most the button moves about 3/4 of the way South-East and I have no idea why. Any help is greatly appreciated.. 回答1: There are a lot of possible solutions using

Disable button on click before actionPerformed is completed java

痞子三分冷 提交于 2019-12-22 09:27:26
问题 I have a button doing a long function, I want to disable this button after the user once click on it to in order to prevent him from clicking it again many times The button gets disabled but the problem is after the function finished the button gets enabled again i tried to put button.setEnabled(false); in a new thread but it didn't work either for testing this sample of code button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { button

Setting Mnemonics and Hot Keys for a JOptionPane Dialog

吃可爱长大的小学妹 提交于 2019-12-22 08:59:55
问题 Is it possible to assign hotkeys and mnemonics to the buttons in a JOptionPane Dialog? I'd like to be able, in a JOptionPane generated message dialog with the options Yes, No and Cancel, press Y to hit the Yes button, N to hit the No button and escape to activate the escape button. Similarly in a dialog with Okay and Cancel buttons I'd like to be able to activate them with enter and escape. I've attempted passing JButtons into the JOptionPane's button Object array with the Mnemonics set