jbutton

Change JButton focus area

左心房为你撑大大i 提交于 2021-02-20 05:14:25
问题 How do i change the area of focus on a JButton so that when i hover my cursor over the button my costume rollover Icon isn't activated slightly before my cursor is over the actual button itself. 回答1: The contains(x, y) method of the button determines when the mouse enters the button. If your custom button is not rectangular then you would need to override this method. Here is an old example that demonstrates this concept: // Old example code found on the internet somewhere // to paint a Round

Change JButton focus area

跟風遠走 提交于 2021-02-20 05:14:15
问题 How do i change the area of focus on a JButton so that when i hover my cursor over the button my costume rollover Icon isn't activated slightly before my cursor is over the actual button itself. 回答1: The contains(x, y) method of the button determines when the mouse enters the button. If your custom button is not rectangular then you would need to override this method. Here is an old example that demonstrates this concept: // Old example code found on the internet somewhere // to paint a Round

Creating a grid layout that holds 100 buttons with 80 empty buttons and 20 random treasure buttons

痴心易碎 提交于 2021-02-11 16:14:07
问题 We are working on a Treasure Hunt game in class as a project. Below is the code that we have so far. I need to randomize where the Treasure Buttons are. My question is: Do I need to create an array that will hold EmptyButton and TreasureButton and then call Random on it or is there a way to create a random layout within the TreasureButton class? Here is our code so far public class TreasureGame { // has-a number of tries private int numberOfTriesLeft = 50; //has-a number of hidden treasure

Creating a grid layout that holds 100 buttons with 80 empty buttons and 20 random treasure buttons

≯℡__Kan透↙ 提交于 2021-02-11 16:12:40
问题 We are working on a Treasure Hunt game in class as a project. Below is the code that we have so far. I need to randomize where the Treasure Buttons are. My question is: Do I need to create an array that will hold EmptyButton and TreasureButton and then call Random on it or is there a way to create a random layout within the TreasureButton class? Here is our code so far public class TreasureGame { // has-a number of tries private int numberOfTriesLeft = 50; //has-a number of hidden treasure

JButton showing up in the wrong spot after repaint is called

不问归期 提交于 2021-02-10 20:21:33
问题 I am trying to add a couple of JButton objects to my GUI program in Java and it is adding them to the JPanel (which is the main file of the program) but it is appearing in the incorrect spot. It is showing op at point [0, 0] and the action that is linked to it is happening at the correct spot. The rest of the elements on the panel are Images so the repaint method is called very often. private void init() { setLayout(null); setBackground(new Color(r, g, b)); addMouseListener(this);

Keystroke/Hot Key for JButton in Java

我是研究僧i 提交于 2021-02-10 07:14:25
问题 Initially I was using JMenu and establishing hot keys to work using accelerator. It was working perfectly. Now I want the same behavior in JButton but I am stuck. Here is the code that I wrote : Please share your ideas so I can go in the right path. import javax.swing.*; import java.awt.Event; import java.awt.event.*; import java.util.Arrays; public class ShowDialogBox{ JFrame frame; public static void main(String[] args){ ShowDialogBox db = new ShowDialogBox(); } public ShowDialogBox(){

Why does a JButton under a JPanel still react?

让人想犯罪 __ 提交于 2021-02-10 03:27:48
问题 I looked around for my problem, and i couldn't find an answer, so here I go: I have a JLayeredPane, and in there there are 2 JPanels. The deepest one ( furthest down ) has JButtons on there. The second one ( The one on top ) has a partially transparent background color ( although i don't think this should influence it ). Now when I hover over my JButtons ( which are behind the other JPanel ), they still fire events to the MouseListener I added to them. I don't know why... Why is this the case

Why does a JButton under a JPanel still react?

£可爱£侵袭症+ 提交于 2021-02-10 03:24:15
问题 I looked around for my problem, and i couldn't find an answer, so here I go: I have a JLayeredPane, and in there there are 2 JPanels. The deepest one ( furthest down ) has JButtons on there. The second one ( The one on top ) has a partially transparent background color ( although i don't think this should influence it ). Now when I hover over my JButtons ( which are behind the other JPanel ), they still fire events to the MouseListener I added to them. I don't know why... Why is this the case

JButton in JPanel with gridlayout

*爱你&永不变心* 提交于 2021-02-08 11:34:36
问题 Is it possible to bring it into this shape using the gridlayout? I use empty label to add this empty grid This is my code: import javax.swing.*; import java.awt.*; public class test { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("Buttons"); frame.setSize(800, 800); int size=12; int flag1=0,count=0,count2=0; frame.setLayout(new GridLayout(1,2,0,0)); JPanel panel = new JPanel(); GridLayout layout = new GridLayout(size,(size*2),0,0); panel.setLayout(layout

Download a BLOB file from database

喜欢而已 提交于 2021-02-08 10:17:10
问题 I need to create a JButton to download a BLOB file from oracle database. This is my JButton code: JButton btnsave = new JButton("Save"); btnsave.setBounds(478, 542, 120, 23); getContentPane().add(btnsave); btnsave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); This class is already connected to database, but here is part of my code: Connection con; String link="*******************************************"; String u="user"; String p="pw"; Class