I'm making a program which includes JButtons with the text "+" and "-" on them. Why does the JButton have an outline around the text within? How do I get rid of the square around the text for a cleaner look?
Image here shows the issue on the first red button.
Use the jbutton.setFocusPainted(false); method.
Related
first time making a question here. First of all, Eclipse (as far as I'm aware of) don't let you re dimension images through the design tab directly so to solve this I made a method that convert the icon from ImageIcon to image, re dimension it and then convert it back. The problem is that when I use the re dimensioned image it looks like this in a JButton.
I have already tried to create a emptyBorder in the JButton but that only remove the border of the button, not the icon. How can I remove it?
Edit:
Just noticed that when the Window is not focused the border is not there? Image related
Just noticed that when the Window is not focused the border is not there?
button.setFocusPainted( false );
Because it wont let me add an image - new account
This is utilizing the Java GUI
The above image is an image pasted onto a button, I've tried to make the button transparent so that the user can't see it but I can't seem to get rid of this blue border.
Code I have so far
boss2 = new JButton(); //declared the static button earlier on in the code
boss2.setSize(300, 300);
boss2.setLocation(315, 200);
boss2.setIcon(new ImageIcon("dragon.gif"));
boss2.setRolloverIcon(new ImageIcon("dragon.gif"));
boss2.setOpaque(false);
boss2.setContentAreaFilled(false);
boss2.setBorder(null);
Is there a way to get rid of the blue border surrounding my image?
edit - sorry for the earlier mishap, uploaded the wrong file
I would suggest that what you are seeing is the focus rectangle, used to "highlight" the button as having keyboard focus.
You can use boss2.setFocusPainted(false); to stop it from been painted.
To not have a boarder drawn for a JButton (assuming that you are using javax.swing.JButton) you can simply do:
boss2.setBorderPainted(false);
I am creating a desktop application in Java with lots of customized UI.
It also has a breadcrumb.
I've extended JButton class to customize it for my Breadcrumb buttons.
This is the screenshot of expected breadcrumb.
http://puu.sh/4MtvZ.jpg
The background of this breadcrumb is an ImageIcon.
But now, I am not able to perfectly align the JButton text over this background icon.
This is the screenshot of actual breadcrumb.
http://puu.sh/4MtDc.png
I've used following code to align the text.
setHorizontalTextPosition(CENTER);
setVerticalTextPosition(CENTER);
So, is their a way that I can move this text in pixels to its right position?
And also, I want root breadcrumb button "Schemes" to overlap some part of its preceding breadcrumb button "2000 Avenues" as shown in expected breadcrumb screenshot!
How can I achieve that?
Check out the Overlap Layout for one solution.
So, is their a way that I can move this text in pixels to its right position?
I don't understand this question. Why are you setting the alignment to center if you want it aligned to the left.
Edit:
I see. You are just using an Icon for the button outline and are then painting the text on top of the Icon. I thought your were using a custom shaped button with text). You can just use the default vertical/horizontal text position settings.
To shift the text to the left you can use:
button.setIconTextGap(10 - button.getIcon().getIconWidth());
My original plan today was to learn how to use the JProgressBar, but now I am stuck with a new problem which I was not expecting. So here is how my JFrame looks like right now.
The problem is that the JTextField right under the JTextArea is not wrapping around. It is going beyond the size of the JFrame. I want it to resize relative to the JFrame. How can i do that? I have tried the JLabel but it does the same thing, only it adds ellipses in the end where the text overflows.
Try using a JTextArea if you intend for the field to expand vertically to accommodate the text.
JTextFields are intended for a single line of text.
In Java Swing I would like to create a JButton which contains an image(icon) and some text. In few words a JButton(text,icon).
I would like the text to be displayed below the image, and not beside, as in normal JButton layout. Does anyone have an idea on how to achieve this?
Have a look at the method setVerticalTextPosition in AstractButton using the constant
SwingConstants.BOTTOM.