How To Make Image Transparent In JLabel And Put On Top Of Another
Feb 19, 2014
i want to make a image transparent and to place it on top of anotherHere's the code:
Java Code:
import java.awt.*;
import javax.swing.*;
public class gameWorld extends JFrame {
public static void main(String[] args) {
new gameWorld();
[code]...
View Replies
ADVERTISEMENT
Mar 25, 2015
How to find coordinates of transparent area in the image. I working on .png image which has transparent background and transparent area in the middle of the image. The transparent area in the middle look a like ellipse, so i want to find coordinate of top, bottom, left, and right of that area. I am using opencv.
I have tried to find pixels and from result that i got, i understand that pixel with rgb that equal to 255.0 255.0 255.0 is transparent. what i have in my mind is, if rgb with value that equal to 255 255 255 detected, i will put 1 into arraylist named transparent, and if it not equal to 255 255 255 i will put 0 into the list. So when i look into the list, if there is 1 0 or 0 1 it means that border between transparent area and colored area or vice versa. But, how to know if that border is between transparent area in the middle of image and the image, and not between background and the image. Am i doing this correctly?
Here snippet of code.
Mat imgMask = Highgui.imread(imgfile);
double[] pixels = new double[3];
System.out.println("channel " + imgMask);
for(int x = 0; x < imgMask.cols(); x++) {
for(int y = 0; y < imgMask.rows(); y++) {
pixels = imgMask.get(y, x);
[Code] .....
View Replies
View Related
Dec 29, 2014
I created an ImageView with an image with transparent portions. I also did some scaling and moving, which I though might cause this effect, but that is not the case. When I click on the transparent portion of the image the onMouseClick event is not fired. Other mouse events (mouse enter, mouse move, mouse exit, ...) get fired. Only when I click on the non transparent part the click event is fired.
Image img = new Image(getClass().getResourceAsStream("barrel_icon.png"));
ImageView view = new ImageView(img);
view.setScaleX(0.5);
view.setScaleY(0.5);
view.setOnMouseClicked(new EventHandler<MouseEvent>() {
[Code] ....
The area between the barrel and the shadow belongs clearly to the image, however is transparent. I am wondering if there is a reason for this behaviour and what is the best way to work around this issue, as my image has large transparent portions and the non transparent parts are hard to click on. By the way this is all based on JavaFX 2.2.
View Replies
View Related
Sep 25, 2014
I am unable to clear disappear the background of .png image added in a translucent JPanel. I have tried it using JLabel but the image added is with white background. How can i get rid of this white background...
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class HomePage
{
JFrame frame;
JPanel pnl1, pnl2, pnl3;
JLabel lbl;
[Code] .....
View Replies
View Related
Jan 13, 2015
I have tried to set a background Image to a calculator usinf JLabel. However I've ended up with my image to the left of my calculator , my calculator textfield becoming the size of the background image and then all my buttons below it.
Like so(if you can view the image)..Calculator.jpg
How can I fix this so the background is behind my buttons and my text area is a normal size again.
My code is below :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Program using SWING components to create a Christmas themed Calculator.
*/
public class GridBag1 extends JFrame implements ActionListener
[Code] ....
View Replies
View Related
Jan 13, 2015
I've tried to add a background image to my calculator , however I have ended up with this ...Calculator.jpg
How do I fix it so the image is behind my buttons etc (as a background) And how do I fix my textarea so it is back to the normal size and not the height of the image? My code is below, please be specific.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Program using SWING components to create a Christmas themed Calculator.
*/
public class GridBag1 extends JFrame implements ActionListener {
private JFrame window= new JFrame("Christmas Calculator");
[Code] .....
View Replies
View Related
Feb 27, 2014
I'm trying to make a JLabel with an image fade in from transparent to fully visible.Is this possible with the JLabel itself or would I have to change the Image? If I'd have to change the Image's opacity how would I do this?
View Replies
View Related
Feb 12, 2015
Why the label wont show the file. The file is located within the project.
View Replies
View Related
Jul 1, 2014
I'm trying to read images and draw them on JLabel. This code snippet below is reading images from a folder
private ArrayList<ShowItem> getData() {
int score = 0;
ArrayList<ShowItem> item = new ArrayList<ShowItem>();
File dir = new File(getImageFolderPath());
if (dir.isDirectory()) {
for (final File f : dir.listFiles(IMAGE_FILTER)) {
BufferedImage img = null;
try {
[Code]...
ShowItem is a class that extends Image. DisplayImage extends ShowItem.
One of the overridden methods in ShowItem is
@Override
public Graphics getGraphics() {
return null;
}
I'm not exactly sure what to do here so I left it.
In another class, where I draw the images on Jlabel. This is what I have:
ShowItem theImage;
private ArrayList<ShowItem> listofImages;
theImage = listofImages.get(random.nextInt(listofImages.size()));
ImageIcon icon = new ImageIcon(theImage);
label.setIcon(icon);
I tried to run it, and check if I'm actually getting the images, and did system out and it listed all the jpg images I have but it's not displaying on the panel.
View Replies
View Related
Jul 30, 2014
This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.
public void actionPerformed (ActionEvent e){
if (e.getSource ==add) {
if (text.getText().equalsIgnoreCase("Exam Schedule")){
link1.setText(text.getText());
link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
[Code] ....
View Replies
View Related
Jul 30, 2014
This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.
public void actionPerformed (ActionEvent e){
if (e.getSource ==add) {
if (text.getText().equalsIgnoreCase("Exam Schedule")){
link1.setText(text.getText());
link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
[Code] .....
View Replies
View Related
Mar 27, 2015
i have very critical problem in my collage project i have try many code but still i cant solve this problem, i want to display image on jlabel or jpanel with respect of components size without use of drawimage method
View Replies
View Related
Oct 27, 2014
I am having trouble making my image move to a certain position in a certain amount of time which is set inside a text file. I was wondering what I'm doing wrong and what I'm missing.
import java.io.*;
import java.util.*;
import java.io.FileReader;
public class Animator {
EZImage HP;
[code]....
View Replies
View Related
Jun 17, 2014
I would like to learn how to add an image background to a window in java that I can put controls like buttons, textboxes, and checkboxes in front of. I already tried using a JLabel with an ImageIcon but I cannot overlay controls over the JLabel. From what I understand there are multiple ways to do this. What is the best way and how can I do it?
View Replies
View Related
Jan 10, 2015
I tried to make a buffered screen image that constantly refreshed an image (a black screen) however it does not seem to be working.
Java Code: import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
[code]....
View Replies
View Related
Apr 9, 2014
I'm trying to add an image on an undecorated JFrame and make it translucent by adjusting its opacity. The problem is that my Image also becomes translucent.
Here is my code:
package Loading;
import javax.swing.*;
import java.awt.*;
public class TransparentFrame extends JFrame{
public TransparentFrame(){
createAndShowGUI();
[Code] .....
How can i make my image opaque but the frame behind it completely invisible. Why I'm getting serialize class warning in this code? that is:
"The serializable class TransparentFrame does not declare a static final serialVersionUID field of type long"
View Replies
View Related
Apr 23, 2015
solve my problems regarding drawings on my JPanel(Transparent panel).My Jframe & other components are created by netbeans GUI builder & the transparent panel is created manually but one problem is that i can't impose this Transparent panel into JFrame like it is attached to the JFrame.Another problem is that,i want that transparent panel size should be counted in inch like my attached picture(TOTAL SIze 36 inch) & also when i clicked on that panel those mouse points highest distance should be measured in Inch.How can i do all of these three task??
View Replies
View Related
Nov 15, 2014
I have a class Tile that extends JPanel within the constructor for Tile I have set the opacity to false so that I can place tiles atop each other and see parts of the tiles below and the background through those parts of the tile that are not being drawn on. This implies that I am using paintComponent within Tile to display the image of the tile I want shown on this object.
The tiles are stacking perfectly. But I find that if I click on a tile through the transparent area of another tile, it is the top tile (transparent area) that retrieves the mouse click. This makes perfect sense, but is there a way to allow the mouse click to pass through transparent portions of the JPanel?
I've considered writing my own method to determine if the mouse click was within bounds then if it was outside the bounds of the object, find a way to pass the click event to the tile below. But this would be extremely challenging if the tiles were implemented as donuts (with holes in the center) or as some other obscure shape with transparent sections.
View Replies
View Related
Mar 27, 2014
I'm working on loading SVG images on Jpanel using "Apache(tm) Batik SVG Toolkit" , but after the image get loaded it has "white background" and "not transparent" one like PNG images.
I checked "fill" of rect attribute on the xml file of the svg image and it was correctly set to none, I also Tested the image on html document and it was trasparent, but in my java app it has white background.
The Question is there any way to load SVG images with transparent background on Jpanel ?
View Replies
View Related
Apr 9, 2014
So what I do normally is draw the bottom layer of grass, and when I draw the second layer with trees, the tree layer has a shadow, that shadow doesn't go ontop of the grass layer, but instead it overwrites the grass layer aswell and I've checked the color codes, the shadow has combined with white, not the first layer.
it's obvious that that's not how alpha works then, how do I do it?
View Replies
View Related
Apr 7, 2014
Sir, I'am new to Swing Programming. I have to create an application where an image is displayed on one Label. The same image has to be split in parts and stored in database pert wise. Later the user has to retrieve the entire image by viewing a small part of the image. I have already displayed the full image on the Label, now i don't know how to split the image and store it part wise in the database.
View Replies
View Related
Jan 5, 2015
I stored an image into MySQL database using swings and hibernate but I am struggling to retrieve that image from MySQL database and display same image in the jTable cell and same as on jLabel whatever I retrieve from the database using swings and hibernate .
View Replies
View Related
Dec 24, 2014
I had string url for image in mysql database and I want show image in mu jsp file bu I can't.
<c:forEach var="urun" items="${listUrun.rows}">
<tr>
<td><c:out value="${urun.kitapresim}" /></td>
<img src="<c:url value="${urun.kitapresim}" /> " width="270" height="190"/>
URL...
View Replies
View Related
Feb 23, 2014
I successfully added a background image on the Panel but I can't create my JButton image on top of my background image.
ImageIcon piano = new ImageIcon("src/img/piano_backgrd.png");
JLabel backlabel = new JLabel(piano);
panel.add(backlabel, new Integer(Integer.MIN_VALUE));
backlabel.setBounds(0, 0, piano.getIconWidth(), piano.getIconHeight());
JButton volup = new JButton(new ImageIcon("src/img/volup.png"));
volup.setLocation(10, 0);
panel.add(volup);
View Replies
View Related
May 8, 2014
We are making a tic tac toe game for my CS120 class and I am having trouble figuring out how to make our X's and O's. Is there a way to make shapes besides making two lines for an X and an oval with a white smaller oval inside to make an O? We have only learned the basics so far in class (i.e. events, inheritance, client-supplier, etc.)
These are our instructions:
Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will 1) create a TicTacToeModel 2) create a TicTacToeView and 3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided (a view of the game, a button, and a text field to enter the cell). A sample screenshot is displayed below.And this is the code i have thus far:
[import java.awt.*;
import javax.swing.JFrame;
public class TicTacToeView extends Rectangle
public TicTacToeView(int x, int y, int w, int h) {
super(50,60,w,h);
this.setBackground(Color.red);
JFrame win = new JFrame("Tic Tac Toe");
win.setBounds(10,10,w+100, h+100);
win.setLayout(null);
win.setVisible(true);
win.setBackground(Color.gray);
[code]....
View Replies
View Related
Nov 21, 2014
I'm trying to make a method that takes an image and turns it into a tile image. So if the original image looks like this:
[URL] ....
then the output image should look like this:
[URL] ....
Here's a method that's supposed to do that but for some reason the output image looks the same as the original:
public static int[][] tile(int[][] arr){
int[][] tile = new int[arr.length][arr[0].length];
for (int i = 0; i < arr.length; i++) {
tile[i]=arr[i];
}
return tile;
}
I recently changed the method and the error message I'm getting is "bad operand types for binary operator '+'. Here's the method:
public static int[][] tile(int[][] arr){
int[][] tile = new int[arr.length][arr[0].length];
for (int i = 0; i < arr.length; i++) {
for(int j=0; j<arr[i].length;j++){
tile[j]=(tile[j])+(arr[i]);
}
}
return tile;
}
View Replies
View Related