jbutton

How can I add a space in between two buttons in a boxLayout?

只谈情不闲聊 提交于 2019-12-17 23:14:55
问题 I have four buttons in a BoxLayout group. This is just a sample of two because it's all repeated code. I want to create a slight space between each button so they don't run into each other. I have tried practically every method in the .add(Box.Create....) and nothing worked. enter.add(Box.createVerticalGlue()); enter.add(Box.createHorizontalGlue()); //enter.add(new JSeparator(SwingConstants.HORIZONTAL)); JButton float = new JButton("LOWER"); float.add(Box.createVerticalGlue()); float.add(Box

How to add to this round button metal background in java?

二次信任 提交于 2019-12-17 21:36:12
问题 How to give this button background to be as jbutton i want to give this button metal color or grediant color how to make that? import java.awt.*; import java.awt.event.*; RoundButton - a class that produces a lightweight button. Lightweight components can have "transparent" areas, meaning that you can see the background of the container behind these areas. @SuppressWarnings("serial") public class RoundButton extends Component { ActionListener actionListener; // Post action events to listeners

How to change font size of JButton according to its size?

不打扰是莪最后的温柔 提交于 2019-12-17 20:39:47
问题 I have a java application - a calculator. I want to resize font of buttons dynamically with resizing the window of the app. How to implement it? My idea is using ComponentEvents. I have initial size of the window of application and initial fonts' sizes. I want to change font size according to button's size, affected by window size change. The problem is how to use the ratio [initial window size] / [initial font size] in the overriden method? The ratio is different for each font. import javax

inside JButton's actionperformed final variables required? [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-17 20:30:57
问题 This question already has answers here : Cannot refer to a non-final variable inside an inner class defined in a different method (20 answers) Closed 6 years ago . So i have a JList and i am trying to use it inside of a JButton s actionPerformed method and it is asking me to make the JList final why is that, below is a code snippet public SomeClass() { btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { list.clearSelection(); }}); } I don't

How to close a GUI when i push a JButton

蹲街弑〆低调 提交于 2019-12-17 20:16:40
问题 Does anyone know how to make a jbutton close a gui? I think it is like System.CLOSE(0); but that didnt work. it also could be exitActionPerformed(evt); , but that didn't work either. just the line of code will work. EDIT: never mind guys. the answer was System.exit(0); . thanks for the help though! 回答1: Add your button: JButton close = new JButton("Close"); Add an ActionListener: close.addActionListner(new CloseListener()); Add a class for the Listener implementing the ActionListener

Weird color changes on hovering on JButton

放肆的年华 提交于 2019-12-17 19:55:44
问题 Ok so this was a problem I stumbled upon when I wanted to use transparency.. So the code for changing background on hover is this... received.setMouseListener(new MouseAdapter() @Override public void mouseEntered(MouseEvent me) { received.setBackground(new Color(50,50,50,100)); } }); At the beginning I set the blue color for the button.. Here's the gif showing the color changes... GifMeme09541718022016.gif https://drive.google.com/file/d/0B9XFyaTVy8oYci1zMmRhMmtYcnM/view?usp=docslist_api Why

How to change text color of a JButton

橙三吉。 提交于 2019-12-17 19:42:18
问题 I am writing a simple minesweeper game and it works now, but I am working on the pretty details like making each number a different color. I keep running into errors when I try to set the text color on the JButton . I can change the text easily enough and the background, but not the text color specifically. The part that keeps getting all mucked up is: total = Integer.toString(count); jb.setText(total); if(count == 1) jb.setTextColor(Color.blue); if(count == 2) jb.setTextColor(Color.green);

Java Swing JFrame Layout

心不动则不痛 提交于 2019-12-17 18:55:01
问题 I just wrote a simple code where I want a textfield and a button to appear on the main frame, but after running all I see is the textfield. If I write the code of the button after the textfield then only the button is displayed. Any idea why? JFrame mainframe=new JFrame(); mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainframe.setBounds(0,0,200,200); JButton jb=new JButton(); jb.setText("Leech"); mainframe.add(jb); JTextField link=new JTextField(50); mainframe.add(link);

JButton background on Nimbus LAF

£可爱£侵袭症+ 提交于 2019-12-17 16:55:12
问题 I use Nimbus LAF and I want to change the background of a simple JButton . JButton jbutton = new JButton("test"); jbutton.setBackground(Color.BLACK); But it doesn't work, when I change the look and feel it works but it doesn't work in Nimbus. How can i do it? Thanks for your help. 回答1: Nimbus uses Painter to paint the different Styles. By Default the Button has a gradient not a single Color. See Button: Nimbus Defaults List You can write your own Painter and override the default. Or you

Adding Buttons inside cell of JTable along with data?

妖精的绣舞 提交于 2019-12-17 16:45:23
问题 Is it possible to add buttons inside the JTable cell along with data? What I am trying to do is to create a table with columns which display data(number) from the database, and two buttons to increase/decrease the number inside the same cell. |ID | Quantity| |06| 2 [+][-] | it would be something like above with [+][-] being buttons. So when I press [+], the number will change to 3 and 1 if pressing [-]. 回答1: Yes, it is possible, although It won't be easy. You have to write your own custom