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.
Related
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.
Hiļ¼there is a problem in my java application, the text in my Jbutton is too long so it only show"..." on the button. Now I want to add some component to help show the actual text on the button.
What method can I use to solve such problem rather than adjusting the text font or button size?
Thank you
Instead of a label, you should add a tooltip to the button:
jb.setToolTipText("The full text of the button");
A small downside is that this tooltip will also be shown if the button text is fully visible, and in that case the tooltip doesn't provide any additional information, which will be confusing. I don't know off my head how to solve this, but it's definitely possible.
I am trying to print particular images(which include some drawn symbols) on textarea when I type a particular Alphabet on my keyboard. How?
You can't use a JTextArea since it can only display text.
You can use a JTextPane as it supports the display of Icons.
Check out: Auto Replace Smiles. It shows how to replace the two text characters :) with an Icon.
You are asking me to do your homework, but still. I will give you only the pseudo code, you will have to write it on your own.
Write a JFrame.
Add a JLabel to the JFrame (using a label is easier than using a text pane, and it is impossible to use a text area).
Add a Key Listener to either the JFrame or the JLabel depending on your application.
In the handler write code to add a ImageIcon to the JLabel when the key you want is pressed or whatever.
Cheers!
I need to be able to select the text in a JLabel. Ive read some guides on the net that talk about using a JTextfield to simulate a JLabel, however this is no use to me as I my JLabel will span multiple lines. So any ideas on how to do this or if it's even possible?
You can use a non-editable JTextArea which allows for multiple lines and selectable text, and visually looks the same as a JLabel.
I do not think it is possible with a JLabel (at least I do not know how)
How do I "combine" JButton with JComboBox and place it on a JToolbar, as shown in this image:
?
You'll want to use a custom renderer I suspect, and have it display clickable buttons (with the appropriate actions attached, etc).
Just create regular combo box and put image as an item. I did it once. Unfortunately I do not have a source code here but as far as I remember it was not a problem. You have to implement your custom 1ListCellRenderer. Its methodgetListCellRendererComponent()` should return for example Label with your image.