Basically, I need an image/icon to show up whenI hover over a swing component
//this is what i normally use to apply image to components
Icon icon = new ImageIcon(getClass().getResource("icon.png"));
label = new JLabel(icon);
what I'd like to do:
//use an imported icon on a tool tip text and also add some texts
label.setToolTipText(icon + "some random text");
Tool tips support HTML, so display that image as you might display it in HTML. E.G. as seen in this answer.
Related
I'm trying to make H3 label, at this point I use built-in Vaadin theme - ValoTheme.This is how i create new label:
Label label = new Label();
label.setCaption("myLabel");
label.setStyleName(ValoTheme.LABEL_H3);
But for some reason, label keeps unstyled.
The question is - how i could stylish Label without using CSS?
Thanks
P.S UI class has been annotated with #Theme(ValoTheme.THEME_NAME)
Update: Making primary button with ValoTheme styling as described above, everything works perfectly.
It took for a while to investigate and found solution that fits me best. The issue has been related to 'label.setCaption(caption);' method, which set components caption, but it denied object customizations.
Thanks to #André Schild for suggestion. So i tested these two small solutions and they worked fine:
Label label = new Label(caption);
label.setStyleName(ValoTheme.LABEL_H3);
and
Label label = new Label(caption);
label.addStyleName(ValoTheme.LABEL_H3);
I hope it helps someone
i got the following java code
Icon icoR = new ImageIcon("src/resources/Republica.png");
Icon icoI = new ImageIcon("src/resources/Imperio.png");
JButton botRep = new JButton("Jedi", icoR);
JButton botImp = new JButton("Sith", icoI);
Object[] options = {botRep, botImp};
//Object[] options = {"Jedi","Sith"};
int i = JOptionPane.showOptionDialog(
null,
"Question","Title",
JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null,options,options[0]);
System.out.println(i);
and im trying to retrieve the selected value from the optionDialog with icon buttons. Problem is, that althought dialog and buttons themselves are properly shown, whenever the buttons are clicked.. nothign happens, and the println statement isnt executed... until i click on the X to close the dialog, and regardless of what i have clicked before.. an 1 is printed as result. Oddly enough, if i change the options array to the regular (text only) one that appears commented in the code, the dialog behaves as one would expect returning the 0-based index of the chosen option. Any hints on what could be wrong here?
thanks in advance
It works if you just pass the Icons, the option pane will create the buttons for you:
Object[] options = {icoR, icoI};
So I guess if you pass the buttons it assumes that you will handle the closing of the option pane yourself.
As a work around you can use the Compound Icon class to create an Icon containing text and your image.
You might also want to use the Text Icon which you can also find from the above link. When you create the TextIcon you will probably need to use:
setFont( UIManager.getFont("Button.font") );
to set the font of the TextIcon to be the same as the button.
I'm using SwingX label for a image select/preview.
I need to show both text and icon together but when I set icon the text disappear!
How can I show text over the icon on a JXLabel?
Thanks
there no issue with that, there are two ways
1.correct way (implemented in the API, good habits, blablabla)
JLabel.setHorizontalTextPosition(JLabel.CENTER);
// search for equivalent in SwingX
2.crazy way to set proper LayoutManager for JXLabel and put there another JXLabel to the desired coordinates Location
I have a few toggle buttons to add styling to text in the form of:
JToggleButton boldButton = new JToggleButton("Bold");
boldButton.addActionListener(new StyledEditorKit.BoldAction());
boldButton.setFocusable(false);
and I also have various styling functions (color, left/right/center align, etc.). What I'm wanting to do is when I call a function (in this case, I'm wanting to basically make a new document) the toggle button is toggled to the off state, and all styling returns to default.
Currently I just set the frame name to untitled (previously the name of the document I was working with), and set the pane text to "", but this keeps all of the styling I had set in the previous document. Is there a better way to do it?
Thanks
boldButton.setSelected(false)
should be all you need.
I need to have a button whose text is underlined and the only way I could find to do this in Java was to use and tags, but when I do this, it causes the button to take up as much room as is left in the JToolBar even though the text is short and it should only take up a small amount of space. Here is how I create the Button.
String buttonText = new String("<html><u>Lesson Plans</u></html>");
JButton lessonButton = new JButton(buttonText);
toolBar.add(lessonButton);
If I remove the tags then it takes up the right amount of space but if I have them in there is takes up the entire toolBar. Anyone know what's going on?
You might be able to fix the problem by using:
button.setMaximumSize( button.getPreferredSize() );
Otherwise you should be able to just change the font to use an underlined font. Darryl's Visual Font Designer shows how to add attributes to a font.
You can overwrite the paintComponent method of your JButton, and write on it with any style and font.
You forgot the closing "" and wrote "" instead... This may be the reason for your problems.