JButton with no background - java

Thank you for your kind, we learned from you many times.
I have xJButton class inherits JButton class.
I am doing this to add an image as icon and change it after it clicked.
I do not want the blue color to be as background and also i don't want any border on it.
Everything is working vine, except the border.
You can see there is 2 borders
setOpaque(false);
setContentAreaFilled(false);
setBackground(null);
can you help me?

You should be able to do it like this:
xJButton.setBorder(null);
xJButton.setBorderPainted(false);
xJButton.setContentAreaFilled(false);
xJButton.setOpaque(false);

Related

Can anyone tell me what components they are in this picture, so I can google it?

Can anyone tell me what component is used to create these titles in a pic?
I want to put multiple titles, which are in red box from the pic, in a frame.
I don't know what components they are.
Hope someone tell me what components they are, so I can google it.
Looks like it's basically a JPanel with a BorderLayout and a raised BevelBorder, then another JPanel assigned to the NORTH border, which has a gradient background color assigned, and inside that panel is a left-aligned JLabel for the title text.

JButton setBackground doesn't work

i try to set Background color of jbutton, but doesn't work? Look at image. Why doesnt work? How to fix?
I want red background :-)
save_button.setForeground(Color.red);
save_button.setBackground(Color.red);
close_button.setForeground(Color.red);
close_button.setBackground(Color.red);
Add to the code for both buttons :
save_button.setOpaque(true);
It should work, if not try disabling the border color

Making the board GUI for a Chinese Chess program

I'm writing a Chinese Chess program in Java and would much appreciate some guidance on designing/implementing the GUI.
The board is to be divided into a 9x10 grid, with an "image" of the chess piece occupying each cell. The cells also need to be 'registered' when clicked so I know which piece was clicked.
1) I'm thinking GridLayout for the layout manager for the JPanel representing the board. How do I add an image to each component?
public void paintComponent(Graphics g) {
Image dog = new ImageIcon("dog.png").getImage();
add(dog)
}
Does not work as dog is not a Component.
2) How would I register for clicks in each cell?
Use a JLabel containing an Icon. Then add the label to the grid layout. Read the Swing tutorial on How to Use Icons for more information.
Also read the section on How to Write a Mouse Listener for listening to clicks on the label.
Or you could use a JButton with an Icon and then use:
button.setBorderPainted(false);
so you don't see the action of clicking the button. Then you would use an ActionListener. The tutorial also has a section on using an ActionListener.
Yes, GridLayout seems appropriate for this use.
See the constructor JButton(Icon).
See this answer for an example that carves up an existing image tile set for use in JLabel and JButton instances.

Color of JOptionPane border

How might I go about changing the color of a JOptionPane's border?
Here is a screenshot of the border I am talking about:
That blue border is what I am trying to get rid of.
I tried to set UIManager.put("OptionPane.border", new BorderFactory...)for LookAndFeel but that changed the inside border, not the outermost one.
I need to get rid of that blue border.
Any ideas?
-Mark
Read the JOptionPane API. It shows you how to create a JOption pane manually so that you have access to the JDialog. Once you have the JDialog you can remove the Border the same way you did in your last question:
Undecorated JDialog border
I have research on it these days, finally I found this code may help you!
UIManager.put("RootPane.frameBorder", new LineBorder(Color.red));
UIManager.put("RootPane.dialogBorder", new LineBorder(Color.red));
UIManager.put("RootPane.errorDialogBorder", new LineBorder(Color.red));
In LaF section there is the initialization of ShadowPopupBorder which used for tooltips, popups, and modal dialogs borders. So check if it is used around your software

Draw something on JButton's right and top corner

I am trying to create JButton such as there must be a number painted on the top and right corner of JButton.
For example, in case of notification buttons there is a message in the button, how is that possible? Can the help be taken of paint method to draw the label?
there are three ways, by using
GlassPane
JLayer (Java7) based on JXLayer(Java6)
JButtton (all JComponents) is container too, there is easy and possible use standard LayoutManagers (only JFrame == BorderLayout and JPanel == FlowLayout have got implemented LayoutManager in API directly), then basically everything is possible
JButton and any JComponent extend Container class, so you should be able to add elements into JButton as if it were a simple panel. So in your case you can add a JLabel with your text into a button.
Also consider implementing Icon to decorate the button; ColorIcon is a simple example. You can use the color to signify buttons that are likely to need attention, and you can use drawString() specify a number.

Categories

Resources