Vaadin - adding text on top of an image - java

I am building a custom layout with Vaadin and I have Images that act as buttons (with a clicklistener). However I also need to display some text and I would like to display it over the image, so inside the image really. Is this possible and if yes, how?
Image dayCourt = new Image(null, new FileResource(new File(basepath + "/VAADIN/images/9_Available_18_Available.png")));

However I also need to display some text and I would like to display it over the image, so inside the image really. Is this possible and if yes, how?
The most straight forward way to do this is to wrap Image and Label (with the text you want to place over the image) inside CssLayout. Then you need to add style name to the label. In your theme you need to set z-index for the Label (so that it floats on top of image) (see: https://www.w3schools.com/cssref/pr_pos_z-index.asp ) and position absolute to Label (see: https://www.w3schools.com/cssref/pr_class_position.asp) relative to corner of the CssLayout
Also, if your Image happens to be static content, i.e. you do not have need to change the image on the fly, you could have even simpler solution. Instead of thinking composite of two components inside CssLayout, you could have only the Label and set the image from theme resources to be the background of the Label (see: https://www.w3schools.com/cssref/pr_background-image.asp).

Related

Dynamic manipulation of font components

I am developing an application to dynamically change the components of a font which is already displayed on screen.
Let me explain this . Suppose I have typed a letter in a certain font style on the screen.
On click of a button I need to change the pixel density on the text to change like this
Is this possible with Java.

Using an image instead of JDialog/frame to hold swing components?

I currently have a JDialog (class that implements JDialog and is constructed like a jframe), and has 3 swing buttons placed on it. Currently I have it set, undecorated = true, to hide the outer frame. Is there any way to use my image to replace the default square frame?
This is what I aim for :
The blue square with shadow is the pre made image.
Regards
The blue square with shadow is the pre made image.
Well, the best way would be to set the background of the panel and then add a ShadowBorder to the panel. This will provide you with far more flexibility in the future as you can create many panels with different colors and reuse the same ShadowBorder instead of having to create an Image every time. I don't have an example of a ShadowBorder, but you might find one if you search the web.
Is there any way to use my image to replace the default square frame?
But if you really want to use your premade Image, then you can just:
create a JLabel and add your Image to the label as an Icon
add the label to the dialog
set the layout manager of the label
add your components to the label.

Can I make resizable the icon inside a jlabel?

Is there any property or any code that I can implement to make an icon inside a JLabel resizable. Or is there any other item which can store an image, that I could use to have a resizable image inside a JFrame?
use this code :
photo = new ImageIcon(UrlofPhoto);
Image im = photo.getImage();
Image Newim = im.getScaledInstance(yourlabel.getWidth(), yourlabel.getHeight(),Image.SCALE_SMOOTH);
ImageIcon Newphoto=new ImageIcon(Newim);
yourlabel.setIcon(Newphoto);
don't forget to set an initialised size to yourlabel
Generally, I would't suggest trying this with a JLabel as JLabel has a lot of other features you really don't want to messing with (alignment and text).
Generally, a better solution is to use a dedicated "image" panel, which you can provide additional control over to fine tune how you want the scaling to work.
For example
If you're really stuck on using JLabel, I would recommend attaching a ComponentListener to it and resizing the underlying image when ever it changes size. The problem with this is componentResized may be called repeatedly in quick succession, meaning you will need to devise some kind of coalescing algorithm that only reacts to the last event within a given period of time...
Check out Darryl's Stretch Icon which will dynamically scale the icon to fill the label.

how to make java run time sizable image box

I'm making a Unicode translator in Java. I did all hard parts, but now I want to add a resizable, relocatable image to the textpane. The user must be able to resize image with its corners and drag & drop the image within the textpane where he likes. (like Microsoft Word or Photoshop)
Something like this:
I tried the Styled Document properties. But I couldn't find way except inserting only an ImageIcon.
May be a better choice would be not to use textPane.
If you have an custom editable label, that can be edited by double clicking on it to show a text box to edit the contents, and change the text of the label when enter key is pressed.
Also give a shot of JDesktoppane, JLayeredPane, and check what components can be added to it.
try this
http://mgeisler.net/downloads/browser/src/ImageBox.java.html
try loading the image inside a JLabel component in JFC Swing.
Otherwise try some other non editable components in the same technology with resizable property.
try this http://sourceforge.net/projects/ird/
the iRD is a component for Resize and move(drag&drop) compoennts on runtime in java.

Align an image in a SWT TableViewer

I just found out, that its somehow impossible to align an image in a swt tableviewer. Creating a TableColumn with SWT.RIGHT (for instance) has no effect on that column if its labelprovider returns an image for it.
Question: Is there any other way to align an image instead of modifiying the image file itself and put some extra pixel into it?
I believe that you're running into a limitation of the underlying platform (or something to that effect). You can have total control over what goes into the cell if you draw it yourself. There is a snippet that shows you how to do this.
Table example snippet: draw images on right side of table item
Of course, you'll also have to draw any text you want in the cell.

Categories