jbutton

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

Calling swing JPanels from actionlistener

孤街醉人 提交于 2020-01-03 04:54:11
问题 im coding a project using various classes, but i got stuck when i press a button which call my main menu, here's my resumed code: My main class: public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { Dimension res = Toolkit.getDefaultToolkit().getScreenSize(); public void run(){ Principal frame = new Principal("Program"); frame.setSize(res.width,res.height); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setUndecorated(true

How to centre the Buttons in my JFrame?

被刻印的时光 ゝ 提交于 2020-01-03 02:26:08
问题 I am trying to make a board game, I have Player 1 label and player 2 label set to the east and west. I am having trouble centre my 3 x 10 buttons. And is there any simpler way of making all 30 buttons at once? Below is my Code: JPanel panel = new JPanel(); JButton button1 = new JButton();JButton button2 = new JButton(); JButton button3 = new JButton();JButton button4 = new JButton(); JButton button5 = new JButton();JButton button6 = new JButton(); JButton button7 = new JButton();JButton

How do I create a JOptionPane.showOptionDialog box in Java (Swing) with custom JButtons?

守給你的承諾、 提交于 2020-01-02 11:03:10
问题 After reading through all the Dialog tutorials for a while, there seems to be no apparent way to do this. The closest thing seems to be JOptionPane.showOptionDialog , but I am limited by the optionType parameter here. EDIT: I figured out the problem, but have a new one. It seems that the options parameter being specified in showOptionDialog needs to be fairly simple objects (strings or just 'objects', not JButton or the like). I was trying to put an array of custom-factory-created JButtons

Getting text value from a jButton

半腔热情 提交于 2020-01-02 10:17:18
问题 So I need to simply check whether a clicked button's text is "X" or "O" (making tic tac toe) This code doesn't work: if (jButton1.getText()=="X") However the following code does work: String jButText = jButton1.getText(); if (jButText=="X") Why doesn't the first bit of code work when the second does? Does it need to be something more like if ( jButton1.getText().toString=="X" )? By the way, I don't think toString exists in Java. That is just somewhat the equivalent in Visual Basic, which is

Getting text value from a jButton

北战南征 提交于 2020-01-02 10:17:09
问题 So I need to simply check whether a clicked button's text is "X" or "O" (making tic tac toe) This code doesn't work: if (jButton1.getText()=="X") However the following code does work: String jButText = jButton1.getText(); if (jButText=="X") Why doesn't the first bit of code work when the second does? Does it need to be something more like if ( jButton1.getText().toString=="X" )? By the way, I don't think toString exists in Java. That is just somewhat the equivalent in Visual Basic, which is

Add icons to JButton using custom font from AwesomeFont and unicode characters in Java Swing?

与世无争的帅哥 提交于 2020-01-02 00:53:19
问题 I have a JButton and I want to add an icon to it. I would like to use the font based icons from FontAwesome which provides a TrueType font file. The icon I am trying to add is the play button icon. The play button icon in the css file for FontAwesome is \f04b which I beleive translates to \uf04b in Java. This is how I am loading the font in the constructor of by IconButton base class. public class IconButton extends JButton { public IconButton() { try { InputStream in = this.getClass()

Can I make Swing JButtons have smaller margins?

笑着哭i 提交于 2020-01-01 07:33:36
问题 I prefer buttons with minimal margins, about as wide as their text caption. Is there a way to achieve that in a JButton in Swing? What I am seeing in practice now is that even if I try to use setMaximumSize() and similar, it just ends up eating the text caption, cutting it off to the right. But it does not reduce the margins. 回答1: I believe setMargin is what you're looking for. myButton.setMargin(new Insets(0, 0, 0, 0)); 回答2: Worth noting you can make the values for Insets -ve. This makes

Is it possible to include JButton in a JTable?

为君一笑 提交于 2020-01-01 02:33:07
问题 I have a JTable that stores the results of a database query, so far so good. What I want is for the last column in each table to have a clickible JButton that will open the edit screen for the object represented in that row, and that means the button will need to know the details of the first column in the table from its own row (the ID from the database). Any advice? I already tried just adding JButtons but they turned into Text when I tried to run it. 回答1: Contrary to the tutorial above,

How to put a JButton at a specific location?

安稳与你 提交于 2019-12-31 07:20:29
问题 I know that there are already very similar questions to my question on stackoverflow, but neither one of them answers my question. I want to put my JButton on a specific location on my JFrame in JAVA. Here is my Code: public class DetectMotion extends JFrame { private JLabel label = null; public DetectMotionExample() { JPanel pnlButton = new JPanel(); label = new JLabel(nothing); JButton btn = new JButton("Close"); pnlButton.setLayout(new BorderLayout()); setTitle("Motion Detector");