jbutton

Arrow Keys Not Working in Custom Search Component

纵饮孤独 提交于 2019-12-24 06:48:07
问题 I am developing a custom search component. When clicked on the button(search image icon) inside the text field, a table is displayed. The code is in very nascent stage so lots of things is not there. As of now, I am stuck because I am not able to navigate the table with the arrow keys. Neither am I able to move to the next text field with "tab" key, once I select a row in the table. The objective of the component is to select a row from the table and then with the help of the supporting

JButton with image background and text alignment

泪湿孤枕 提交于 2019-12-24 06:38:26
问题 I've got (again) a problem: i got a jbutton with an image on background, but when i want to put some text on it, it will apears on the right side of background, not in button, but aside... Here is working code, you must only link some image :) package program; import java.awt.Image; import java.awt.Insets; import java.io.File; import java.io.IOException; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing

Stopping JButton highlighting on press

主宰稳场 提交于 2019-12-24 04:35:10
问题 Any JButton that is pressed will seem to "highlight" itself when pressed like so: I can't seem to find any way of disabling this. 回答1: You can extend JButton class and design your own appearance or just override the default bahaviour as in this exemplary code: public class MyButton extends JButton { @Override public void paintComponent(Graphics g) { super.paintComponent(g); if (isSelected()) { setBorder(BorderFactory.createEmptyBorder()); } else { setBorder(BorderFactory

Java Key Event won't execute once I press a button

走远了吗. 提交于 2019-12-24 02:04:00
问题 Hi hope someone can tell me what I am doing wrong with my Key Event. I am using a Card Layout to navigate through two of my JPanels atm. To do so I use Action Events as well as Key Events. The action events will toggle between JPanels when a button is pressed while the key events will hide away the buttons when a key is pressed. All good with the key events, it does what I want (call a method on one of the panels to set the bounds of the buttons placed inside it eq: button.setBounds(-1, -1,

Java Key Event won't execute once I press a button

↘锁芯ラ 提交于 2019-12-24 02:03:43
问题 Hi hope someone can tell me what I am doing wrong with my Key Event. I am using a Card Layout to navigate through two of my JPanels atm. To do so I use Action Events as well as Key Events. The action events will toggle between JPanels when a button is pressed while the key events will hide away the buttons when a key is pressed. All good with the key events, it does what I want (call a method on one of the panels to set the bounds of the buttons placed inside it eq: button.setBounds(-1, -1,

JButton Release Action

筅森魡賤 提交于 2019-12-24 01:56:21
问题 I am trying to create an action on a JButton release and I am not sure how to accomplish this. I can make an action just fine when the button is pressed. When the button is pressed it will change the image to a red dot and when released it should change back to a default green dot. My button press code is below if someone can point me in the direction on how to create an action when the button is released that would be most helpful. Thanks! @Override public void actionPerformed(ActionEvent e)

Java: JButton with custom Shape: Fill with Metal Look and Feel Gradient

走远了吗. 提交于 2019-12-24 01:53:30
问题 I have a new class derived from JButton which gives me the shape of a Enter-Button. Now I want to have it filled with the same gradient as the default JButton . But I do not know. How I can do this? At the moment it is filled with plain black color. import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Polygon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class EnterButton extends JButton { private Polygon

Text is greyed out when JButton is disabled

允我心安 提交于 2019-12-24 01:18:38
问题 I'm making Minesweeper for a school project. When a field/button is clicked, it gets disabled, and it shows its neighbors with a different color depending on the number of neighbors it has. I'm working on this in Eclipse. It works all perfectly and I'm almost ready to submit it. The only problem is that the colors work when run in Eclipse and JCreator, but when I run it with a .bat /command ( java Minesweeper ), the numbers show up greyed out instead of colored. I change the colors with html

How do I position JButtons vertically one after another?

六月ゝ 毕业季﹏ 提交于 2019-12-24 00:13:30
问题 I used a CardLayout to create 2 panels. The one on the left hosts JButtons , which when clicked, opens the corresponding website in the right panel. The problem is that I'm unable to place the buttons one on top of the other. Please observe the screenshot below :- 回答1: "The problem is that I'm unable to place the buttons one after the other." You could use a Box set vertically JButton jbt1 = new JButton("Button1"); JButton jbt2 = new JButton("Button2"); JButton jbt3 = new JButton("Button3");

How to determine the event source in an ActionListener?

纵饮孤独 提交于 2019-12-23 20:34:53
问题 Ok. I'm not sure about the title of my question and whether I used the right words. As I am a self taught total amateur I'm finding it hard to ask my question as I don't know the correct terms for things so I will write something in code and then ask my question. I've written it without import statements, setting up layouts and scrollbars and some other things just to keep it simpler. public class Foo{ JTextArea text; public static void main(String[] args){ Foo foo = new Foo; foo.go(); }