Moving JButton text over its icon by pixels - java

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());

Related

Swing JButton: Icons and text in one position

Is it possible to use JButton I can put the text is right in the icon, not above, below, left and right side of the icon. If possible how?

Text Not Aligning To the Center of JLabel in Java

I have a JLabel on the bottom of my panel that gives text instructions to the user. Some of the text went off the screen because it was too long. To fix this, I added tags. However, now the text is no longer centered, it is now aligned to the left. Why is this case. Shouldn't this code center the text?
detailedInstructions.setText("<html><div align=center>" + test.getMicroSteps()[currMicroStep].getDescription() + "</div><html>");
Instead of using HTML code, simply call
detailedInstructions.setHorizontalAlignment(SwingConstants.CENTER);
Or use the JLabel constructor that sets the horizontal alignment.
Note that if the JLabel displays an ImageIcon, then you'll also want to set it's horizontal text position which determines the location of the label's text relative to its image.
Other potential issues is that the JLabel itself might not be centered at teh bottom of the GUI. To test this, put a border around the label to see it's actual placement, and if so, then you will need to work with the settings of the label's container's layout manager.

How to get tab pane tabs rotated and visible when oriented on the left side?

I am currently trying to get the tabs on the tab pane to be rotated 90 degrees and visible completely.
My attempt has ended in this
Image
I was able to rotate it by adding a rotate styling to the tab itself, but i cannot resize the anchorpane, or tab at all.
After googling for a long time, I could only find this http:// javafx-jira.kenai.com/browse/RT-19547. It says that the only way they could do it is to "put the text into the tab's 'Graphic' to achieve this". I'm not sure what that means or how to accomplish that.
My end goal is to create tabs that have the same shape and feel as these (image)
In this solution:
http://oreilly.com/pub/a/mac/2002/03/22/vertical_text.html
The text was painted vertically and tried as an icon on the tab. This way you don't have to modify JTabbedPane you just use a custom Icon in the tab.
Of course you would also have to specify the tab placement to be on the Left.

Getting graphical buttons to line up in xml

I have a custom popup window with a custom image background in which I need to place three custom buttons with their own background images. I have only one set of images for all the components, so I want all the parts to scale appropriately. My question now is how do I make sure that the buttons line up with the appropriate parts of the background image of the popup window. I have been experimenting with all sorts of widths and heights and I can not make it look consistent on all my test devices. Can anyone give me some pointers?
EDIT: Just to make it as clear as possible, the image below illustrates the kind of thing I am talking about:
I want the graphical button to line up with the arrows which are a part of the popup window background image.
arrange buttons in an xml layout and set this view to your custom popup and you can set images to buttons from code.

can I rotate the button or label into vertically in java?

I want button in vertically, for that i can extend the height and shrink the width of that button. But the text of the lable of buttons are in the form of horizontal only. For that can i rotate the whole button vertically and is it possible?
Rotated Icon shows how the text and icon can be rotated on the button (or any component that uses icons.
The easiest way to do this would be to pre-rotate the labels and just have it as an image on the button.
You might also want to take a look at this solution given in sun's forum for rotating a JButton.
You should be able to do this with scene graph: https://scenegraph.dev.java.net/

Categories