How To create Transparent buttons on libgdx - java

I am trying to make a transparent button how to do that in libgdx
i tried https://github.com/cobolfoo/gdx-skineditor this skin editor but couldnt do it either

If you need buttons with concrete percentage of transparency and then you will not change that percentage anymore it's much easier to create the buttons images with desired transparency level in some graphics editor (e.g. Photoshop) and then use them in your project.

Related

How to give a button a custom shape in Java Swing?

I'm new to Java Swing, I searched a lot about this question on stackoverflow.com and other websites, but couldn't find a concrete answer, so I decided to ask it myself. I want to create a JButton of a custom shape - of the map of the USA. I have a png image with a transparent background. I know that
usaButton.setOpaque(false);
usaButton.setContentAreaFilled(false);
will get rid of border of the button and remove the background color, but I want it to create a border around the map itself whenever I hover my mouse over it, not a rectangular border around the button. This is the map just for the reference:

Making a hole in a JFrame

I was trying to make a simple GIF capturing app, but I needed to make a hole/transparent space in a JFrame based on a JPanel.
I tried many things, from per-pixel transparency (only works with undecorated windows...), custom shapes (again, undecorated windows only), etc...
This is what I want (edited):
This is what I have:
In .NET Framework, it's as simple as setting the TransparencyKey color of the form, and setting the panel's background color to that color.
I'm wondering if this is possible....

Java Swing : best way to set background image clickable

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.

Positioning a label using swing in java

I have been using jFrame to build a GUI. I had to insert images in the GUI, for which i inserted a label and put the image as an icon for the label. Now, i have to find out the position of the image in terms of the x and y co-ordinates and i am unable to do that. I have used
setLocaction(x,y);
but it still doesn't seem to work. I even disabled the layout manager by using
setLayout(null);
What is the possible solution for this problem?
Edit
Basically i am creating a Solar system GUI using Swing, so the positions of the planets are to be set by me. I being new to java, there is being some difficulty in implementing the layouts.
This isn't a layout issue at all, but a drawing and possibly an animation issue. If this were my project, I'd
First and foremost, separate out the program logic from its display, a la the MVC or Model-View-Control pattern, or one of its many variants.
Create one JPanel for the GUI's graphics and do all my drawing in this
I would not display my planet images using ImageIcons inside of JLabels.
Rather, I'd create a background image and draw my planet sprites inside of the drawing JPanel's paintComponent method.
I'd create non-GUI Planet classes that a non-GUI model would hold.
In the GUI portion of my program, I would associate a BufferedImage with each Planet, probably using a HashMap<Plant, Image>.
I'd then draw each Planet's associated image in the drawing JPanel's paintComponent(...) method, and place it depending on the Planet's position field values.
If I wanted to animate this, I'd use a Swing Timer to drive my simple animation.
With null layout you should use setSize and setLocation methods on you label to get your image visible correctly inside your frame.

Change Jframe Shape

In c# you could change the form shape to be as some picture shape that you draw..
I wonder if there is the same option to do this on jFrame in java? (I'm using netbeans)
and for example this is the picture I want to be used as the jFrame shape
so inside the "phone screen" I want to add some buttons.. is it possible?
See How to Create Translucent and Shaped Windows for details & especially How to Implement a Shaped Window.
Android Look and Feel
Everything on an Android screen is a rectangle. Widgets are rectangles. Launcher icons are 96 x 96 pixel squares. The text under a launcher icon makes them a rectangle.
The screen resolution of a Samsung Galaxy S3 is 1,280 x 720 pixels. The screen resolution of my 22" Samsung monitor is 1,680 X 1,050 pixels. You're going to have to turn the "phone" on its side and use your entire display to get the sharpness of the text on the S3.
This would be a great look and feel for a dashboard application. Your users are probably already accustomed to the smart phone appearance. Obviously, the gestures in your Swing application would have to use a mouse.
GUI Design
First, you create an ordinary JFrame.
Second, you create a drawable JPanel by extending JPanel and overriding the paintComponent method. You would paint the background image on this JPanel, then paint the launcher icons. The launcher icons are BufferedImages created from PNG files, so they can have transparent areas.
The drawable JPanel would listen for mouse clicks. This is so the launcher icons can be moved, and also so the launcher icons can be executed.
The Java application launched would replace the drawable JPanel with it's own JPanel. You would have to follow the Android developer guidelines in developing these JPanels, so your users feel like they're in an Android look and feel. Each application JPanel would have to be 1,280 x 720 pixels.
Your GUI model would hold all of the launcher icons, as well as the positions of these icons for each user. A relational database could hold all of this information so each user would have his or her own display.
Apps / Widgets
I hadn't worked out all the details in my mind, but there would have to be an Apps / Widgets drawable JPanel that shows all of the launcher icons and widgets. The user can drag the launcher icons from the Apps JPanel to the main drawable JPanel.

Categories

Resources