jbutton

get position of the button on gridlayout

浪子不回头ぞ 提交于 2019-12-20 07:51:45
问题 How to get position(I mean row and column) of the clicked button with gridlayout? public void init(final Container pane) { JPanel controls = new JPanel(); int size = (int) Math.sqrt(puzzle.getSize() + 1); controls.setLayout(new GridLayout(size, size)); for (int i = 0; i < puzzle.getSize(); i++) { int k = puzzle.getListItem(i); if (k == puzzle.getEmptyFlag()) controls.add(new JLabel("")); else { JButton jb = new JButton(String.valueOf(k)); jb.addMouseListener(new MouseAdapter() { @Override

Swing: taking variables from two private jTextField?ActionPerformed classes

让人想犯罪 __ 提交于 2019-12-20 07:48:20
问题 I'm in NetBeans 8.2 and I've constructed a nice jFrame GUI for a Binary-to-Decimal converter, I think I have the code in my two text fields correct but I can't figure out how to access the variables for my Button to perform operations on. I have 3 method operations called parseBinary, isBinary, and illegal that I want to use to perform operations on my two text fields. In NetBeans when you code a button the method is locked to private so that's my issue. I will post all my of code and

JFrame does not add component when JButton is pressed

断了今生、忘了曾经 提交于 2019-12-20 06:39:50
问题 My code is basically about having a frame and it has a button. You press the button you can draw rectangles, getting coordinates from the mouse press and the mouse release. Now, if you remove the button the code works perfectly, here is the code. //testing file package ActionTest; import java.awt.*; import javax.swing.*; public class MouseTest { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { JFrame frame = new MouseFrame(); frame.setTitle(

setText to Jlabel with function

ⅰ亾dé卋堺 提交于 2019-12-20 06:26:12
问题 I am trying to settext to JLabel with a function. The checkResults function is not working for some reason I still get errors. I have 2 classes Driver and MathProblems Driver Class import java.awt.EventQueue; import java.awt.GridLayout; import java.awt.event.*; import java.util.Scanner; import javax.swing.*; public class Driver extends MathProblems { MathProblems answers = new MathProblems(); MathProblems problems = new MathProblems(); private static final Scanner in = new Scanner(System.in);

several times change label text by clicking button in swing not work

岁酱吖の 提交于 2019-12-20 06:18:21
问题 I need to change jlabel.text several times by one click button in swing. In this code i need set label text to start before dowork() function and set to in progress in middle and set it to end after dowork() (status type in jlabel and dowork has long time execution) : private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { status.setText("start"); try { Thread.sleep(10000); } catch (InterruptedException ex) { Logger.getLogger(PelakInRFID.class.getName()).log(Level.SEVERE, null,

Keyboard Press and Jbutton

三世轮回 提交于 2019-12-20 04:55:19
问题 I have an calculator app and I am having trouble using setMnemonic. I am trying to get the keys on the keyboard to link with the buttons on the calculator. It keeps telling me < Identifier> is expected. This is the page I have been getting the info from about the function http://docs.oracle.com/javase/tutorial/uiswing/components/button.html. Any ideas how I can get it to work? 回答1: Your problem has nothing to do with Swing or mnemonics and all to do with trying to make method calls outside of

change buttons backgroundcolor in awt

时间秒杀一切 提交于 2019-12-20 03:39:06
问题 So i have a GUI program called Safe25. Basically, if you press the buttons in the right order which is "15032018" the program closes itself. If you input a correct number, lets say you press 1 at the start, the buttons should change their backgroundcolor to green like this: If you press a wrong button, the buttons should change their color to red. But the logic of my code is irrelevant for my problem. As i said, i want to change the buttons backgroundcolor like in the linked image. My problem

JButton.setBounds(x,y,w,h) doesn't seem to work

十年热恋 提交于 2019-12-20 03:18:01
问题 import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingUtilities; public class SimpleExample extends JFrame { public SimpleExample() { setTitle("Simple example"); setSize(500, 500); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); JButton jb = new JButton("TEST"); jb.setBorderPainted(true); jb.setBounds(5, 5, 1, 1); ---> This line add(jb); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void

Adding button to jtable

拥有回忆 提交于 2019-12-20 02:34:28
问题 I searched for tutorials for adding button in jtable and found a class file from, http://tips4java.wordpress.com/2009/07/12/table-button-column/ Where to set label for the button? [code] private void createTable(){ model = new DefaultTableModel(); editorTable.setModel(model); model.addColumn("COL1"); model.addColumn("COL2"); model.addColumn("ADD"); model.addColumn("DELETE"); model.addRow(new Object[]{"DATA1", "DATA2"}); Action delete = new AbstractAction() { @Override public void

Dynamically change jButton icon

﹥>﹥吖頭↗ 提交于 2019-12-20 02:33:22
问题 I have a program that detects when certain machines are online and creates a button with a green "online" icon to show this. I want to add the functionality to check periodically if this machine is still online, and if it's not, change the icon to the "offline" icon that I've already defined. 回答1: I know how to set the icon, however I can't figure out a way to do it once the button has already been displayed probably you have issues with Concurency in Swing, that means that all Swing code