Is it possible?
For example I have JTextfeilds which i use to label an image via a mouse pressed listener(makes new label every time the mouse is clicked).
I then move on to the next image and add more label(the images are attached to the JSlider).
So what im asking is whether or not it is possible to attach the labels i create for each image to the jslider? or possibly the image?
At the moment when i create new labels on the next image it keeps them when i return to the previous image.
Any help would be appreciated.
The images are depends on the JSlider by the user uploading a folder of images, the image names then get put into a list. Using a loop i then change which image is shown depending on the slider value.
1 partially labelled image
So this is the first images labelled with JTextfeilds.
New labels added on new image
This is a new image with some added labels, what i want to be able to do is return to the previous image without the new labels, while being able to go back to this image with the new labels.
Related
I have a Codename One App that has Images in it.
However, whenever I'm trying to scroll when the cursor is on the image it doesn't work.
Edit:
1: (Some Component) Scrolling works;
2: (Image) Scrolling doesn't work
Link is HERE
Image img = Image.createImage(FileSystemStorage.getInstance().openInputStream(i.getImagePath()));
imgViewer.setImage(img);
imgViewer.setHeight(img.getHeight());
imgViewer.setFocusable(false);
This is the code that creates the ImageView.
The Image View is inside a Container which has the Layout BoxLayoutY (vertically scrollable)
That Container is in the Form which is the most bottom Layer, also set to BoxLayoutY
I suppose there must be some function that I can call to make it possible to scroll when the cursor is on an image, but I have no idea, which one that is.
Don't use ImageViewer use Label or ScaleImageLabel. ImageViewer grabs your pointer events to pan the image and allows zooming into it. It's designed for use over the entire Form and won't work well in a scrolling scenario.
If you want that functionality I suggest putting a small thumbnail in a Button then when it's clicked show the ImageViewer in a separate Form at the center of a BorderLayout.
I have button on frame. On that button I put an image, which as you see that is a search icon. I remove the visible border on the button. But still I have two questions:
when I put the mouse on the button, the image and also the invisible button border is clickable, what I need is restrict it just on the icon.
I want to make the icon focusable by clicking like click on the simple button.
Search Icon:
What sort of image file format are you using? If it's a format with transparency support, you'll have to implement an algorithm that checks whether the click coordinate is inside of the non-transparent pixels of the icon you're using. You'll have to offset the rgb checks on the image pixels by the position of the image on your frame as well. Use this as a reference - Java Image Processing
I try to find the best way to make an image clickable with different action depending on the area you click. For now, my window display an EFTPOS (image found on google image) using :
getContentPane().add(new JPanelBackground("./img/background.png", "./img/eftposAboveBackground.png", this.getWidth(), this.getHeight()));
Now, I would like to click on every EFTPOS's buttons. I was thinking of create some transparent buttons at the buttons's positions but :
First, I don't want to use an absolute layer
Second, the Swing GUI design editor (Netbeans) doesn't display my background image since I used the code above.
I'm pretty sure there is another way than setting my eftpos on the background, maybe using the ImageIcon class..
Any help would be greatly appreciated!
You can to create an ArrayList of Rectangles (or Shapes) to represent the area of each button on the image.
You need to add a MouseListener to the image.
In the mousePressed() event you need to iterate through all the Rectangle in the ArrayList using the Rectangle.contains(mouse point) method to see if the user clicked in a Rectangle.
When you find the Rectangle that was clicked you execute your custom code.
A have a list with small thumbnails and want to show a fancy tooltip with a larger version of the image of the thumbnail left to the thumbnail if one hovers with the mouse over the thumbnail. If one drags the mouse down to the next list element the old tooltip should disappear and a new tooltip next to the new cell should appear.
Unlike the existing text tooltip javax.swing.JComponent.setToolTipText(String) my fancy tooltip should always be displayed left of the current column. The problem is, that this is a very complex relative layout I cannot change for this. The fancy tooltip should appear above all other components like the real tooltip does too, i.e. I cannot reserve some free space for it.
I took a look in the implemenation of the real tooltip and think about something like getting the absolute coordinates of the mouse mouseEvent.getX() and subtracting the position inside the thumbnail to get the right corner of my fancy tooltip. Is it possible to get the coordinates of the mouse event inside the component where the listener is registered? Any better ideas for my needs?
I thought java.awt.event.MouseEvent.getX() is the absolute point, but thats java.awt.event.MouseEvent.getXOnScreen(), i.e. this is already the answer...
I'm writing checkers. So, every cell is JButton, it has image (ImageIcon).
I want JButton that has background image and backlighting (for example, blue of red), because I want to show user available turns. Is it possible?
Now if I create new JButton(Icon icon) and then setBackground(Color.BLUE);
background is ignored.
You should set its border color to BLUE or RED (I believe this is what you are looking for as an answer)
Try this statement:
chessButton.setBorder(BorderFactory.createLineBorder(Color.GREEN));
Painting JButton's border is not effected by image icon, therefore if you want to create a highlight effect and set border's color you should use BorderFactory. You can also have various effects for the border through BorderFactory
If you want complete background highlighted or some special effect then have two separate image of each cell i.e. one normal image and one highlighted image. When you want to show user its available turns, simply update the respective cells with their corresponding highlighted image