jbutton

Variable name of Swing component in Netbeans

爱⌒轻易说出口 提交于 2020-01-05 05:40:45
问题 I have an application that is currently using over 200 buttons, each of which returns the String of their variable name. Is there any way to do this? Setting the name property for each of these would be far too time consuming. 回答1: Use a collection of buttons: ActionListener theActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println(((JButton) e.getSource()).getName()); } }; List<JButton> buttons = new ArrayList<JButton>(); for (int i

Variable name of Swing component in Netbeans

牧云@^-^@ 提交于 2020-01-05 05:40:34
问题 I have an application that is currently using over 200 buttons, each of which returns the String of their variable name. Is there any way to do this? Setting the name property for each of these would be far too time consuming. 回答1: Use a collection of buttons: ActionListener theActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println(((JButton) e.getSource()).getName()); } }; List<JButton> buttons = new ArrayList<JButton>(); for (int i

Increasing distance from top of JPanel

爱⌒轻易说出口 提交于 2020-01-04 14:23:28
问题 I'm trying to increase the distance of my JButtons from the top of my Panel to make it more visually appealing, i've tried using an invisible button but have had no luck. public class SimpleBorder { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(500,500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border etched = (Border) BorderFactory.createEtchedBorder(); String[] items = {"A", "B", "C", "D"}; JList list = new JList(items); JTextArea text =

JButtons inside JPanels, fill up the whole panel

痞子三分冷 提交于 2020-01-04 06:31:30
问题 I've been struggling to set a specific size to a button inserted into a JPanel with a GridLayout. The button always fills up the whole panel, whereas if I remove the gridlayout, the button won't have the same behavior. any hints? package panels; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing

JPanel and JButton, cannot figure how to layout 2 simple buttons

和自甴很熟 提交于 2020-01-04 05:26:35
问题 i am starting with JPanel and i am trying to put 2 simple buttons on a frame, i was able to put the buttons but not position them, here is my code: JFrame frame = new JFrame(); frame.setSize(500,500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton but = new JButton("text"); JButton but2 = new JButton("list"); JPanel panel= new JPanel(new GridLayout(1, 2)); panel.setSize(100, 100); panel.add(but); panel.add(but2); frame.add(panel); frame.setVisible(true); and here is a sketch of

Change Border Color of a JButton in Java Swing preserving the insets

情到浓时终转凉″ 提交于 2020-01-04 02:15:08
问题 I want to change the border color of a JButton component in Java Swing. I have tried the following: package com.example.test; import java.awt.Color; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class Test extends JFrame { public Test() { JPanel panel = new JPanel();

JButton alpha background change with mouseover

你说的曾经没有我的故事 提交于 2020-01-03 20:04:13
问题 I want to have 2 buttons on my application with a transparent background and I "almost" done it. This is what I've done : public class PanelMenu extends JPanel{ //VARIABLES private JButton buttonFightSimulator, buttonMatchUp; //CONSTRUCTORS public PanelMenu () { this.setBounds(0,0,240,768); this.setLayout(new FlowLayout(0, 0, 0)); //BUTTON CREATION buttonFightSimulator = new JButton("FIGHT SIMULATOR"); buttonMatchUp = new JButton("MATCH UP"); buttonFightSimulator.setBackground(new Color(255

Create an array of JButtons with the Netbeans 6.5 GUI Builder

自作多情 提交于 2020-01-03 18:21:51
问题 I want to create an array of JButtons with the GUI Builder (not actually writing the code, but drawing it). I can only figure out how to change the name of the element, not add it to an array. Thanks. 回答1: http://wiki.netbeans.org/FaqGuiControlArray 回答2: I think you'll find doing much "programmatically" will go beyond most GUI builders, other than for specific programmed-for exceptions. 来源: https://stackoverflow.com/questions/746325/create-an-array-of-jbuttons-with-the-netbeans-6-5-gui

Create an array of JButtons with the Netbeans 6.5 GUI Builder

泄露秘密 提交于 2020-01-03 18:21:28
问题 I want to create an array of JButtons with the GUI Builder (not actually writing the code, but drawing it). I can only figure out how to change the name of the element, not add it to an array. Thanks. 回答1: http://wiki.netbeans.org/FaqGuiControlArray 回答2: I think you'll find doing much "programmatically" will go beyond most GUI builders, other than for specific programmed-for exceptions. 来源: https://stackoverflow.com/questions/746325/create-an-array-of-jbuttons-with-the-netbeans-6-5-gui

Overlay a JButton over JLabel in Java Swing?

爱⌒轻易说出口 提交于 2020-01-03 11:47:07
问题 Is it possible to overlay a Button over a Label in Swing? For example, if have a JLabel with image and no text, and i want to overlay my button over this JLabel. Label is defined something like: myLabel = new javax.swing.JLabel(new ImageIcon( myPicture )); If not, then any ideas how can i realize this, thank you. EDIT: Actually i read about adding JPanel to a JLabel, when i add a Panel with button layout, it compiles fine but nothing is visible, just the JLabel with image UPDATE: As suggested