Relative Content

Tag Archive for javaswing

Java drawing opaque rectangle on transparent JFrame

I am trying to draw an opaque rectangle on a transparent JFrame to implement a “screen capture” type of program, but I’m having a few difficulties. The first difficulty is that the rectangle is only drawn when I’m moving the mouse while dragging but it goes away when I don’t move my mouse. The second difficulty I’m having is I’m not quite sure how to make the rectangle a different opacity than the frame. Here is the code I have so far

How to change the Icon of a JLabel dynamically?

I’m using the Swing library and the ApacheNetBeans IDE for a project at my school. The following code is for a method that needs to simulate a dice roll; I want a JLabel (which represents the dice) to have its Icon changed sequentially, a few times. Each Icon is one side of a piece of dice.

Why does setPreferredSize not work in my code?

While trying to create a panel for my game, I am trying to use a number of things such as setPreferredSize, setBackground, and more, but for some reason all of these are being underlined. Also, I’m following this video: https://www.youtube.com/watch?v=om59cwR7psI&t=702s and I have been following the steps very closely so I’m not sure why it isn’t working for me.

Gap between menu items in Swing

I have a ComboPopup implementation, it’s a JPopupMenu wrapper. It has two stacked elements, the upper of which, a JTextField, is optional