Java transparent JPanel (allwaysOnTop) triggers Taskbar - java

I recently wrote a program in Java, that functions as a game-overlay (in order to create custom gamemodes in games like Rainbow Six: Siege) by applying the following settings:
clientFrame = new JFrame("Window");
clientFrame.setSize(400, 300);
clientFrame.setUndecorated(true);
clientFrame.setBackground(new Color(0,0,0,0));
clientFrame.setAlwaysOnTop(true);
clientPanel = new JPanel();
clientPanel.setOpaque(false);
textArea_Messages = new JTextArea();
textArea_Messages.setEditable(false);
textArea_Messages.setBackground(new Color(0,0,0,0));
textArea_Messages.setFont(font);
clientPanel.add(textArea_Messages);
clientFrame.getContentPane().add(BorderLayout.CENTER, clientPanel);
clientFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
clientFrame.setVisible(true);
clientFrame.pack();
This worked for me the last few months. I had to run the game in borderless window mode in order to display the panel on top of my game, but I was able to Alt+Tab out of the game to change some gamemode settings and reentering it by clicking inside the game window. My JPanel stayed allways on top, and the taskbar disappeared while playing.
Today I noticed that the taskbar doesn't hide anymore. Either it stays on top together with my JPanel, or the JPanel (and the taskbar) aren't visible. I've searched online for hours trying to solve this issue and tested everything (Repinnig every icon, Restarting Explorer.exe, changing the taskbar-preferences...).
However, when checking the "Allways on top" option in the Task-Manager, the taskbar disappears while playing! This leads me to the assumption that the JPanel somehow keeps the taskbar in focus, while the taskmanager doesn't.
Does someone know what causes this issue?
Some more information that might be relevant:
-The game got an update a few days ago
-I was using Classic Shell all the time
-Windows got an update that forced me to reinstall Classic Shell
I know, my problem does not sound that terrible, but I'm recording my custom gamemodes for Youtube and the taskbar is really annoying.
Thanks in advance :)

Related

Maintaining PowerPoint in full screen while cliking in JFrame

I am working on an application that consists of a JFrame that runs on top of Microsoft PowerPoint. It is an invisible frame so that you can see what PowerPoint is showing. This frame has certain buttons that I want to be able to click, while a PowerPoint presentation is on "PowerPoint presentation mode" (full screen).
The problem is that, when I click a button in the frame, PowerPoint minimizes. I want PowerPoint to be kept in full screen while I click the buttons. This is the code I used to set the frame to be in front of PowerPoint.
jframe.setUndecorated(true);
jframe.setBackground(new Color(0, 255, 0, 0));
jframe.setVisible(true);
jframe.setResizable(false);
jframe.setAlwaysOnTop(true);
Some of the solutions I considered were:
Tried using jframe.setFocusable(false); so that the focus is maintained in PowerPoint app, instead of changing to my app. I also used that method in the JPanel and the buttons that are in the frame. But it doesn't seem to do the job.
This second solution works, however it is a bad one. When pressing one of the buttons, it minimizes PowerPoint, afterwards I use java Robot class to press cmd+tab (or alt+tab in windows) and since the last app that had the focus was PowerPoint, it comes back into full screen and my app is still on top. The problem is that the user will notice that, and there should be an easier way around this.

Robot focus in minimized frame

I'm using at the moment the Robot class of the AWT library for a Java Frame.
But when I minimize the frame, the robot will still type and using the mouse in another application that isn't even written in Java.
How can I set the focus on the frame only and when I minimize, it'll still continue?
How can I set the focus on the frame only and when I minimize, it'll still continue?
You can't. By design a minimized frame does not have, and cannot get, focus.
You might be able to 'hack it' by making the frame go almost transparent when asked to minimize, though that will block input to any window that is behind it, and will fail if another is in front.
That's the whole point of Robot. It would be a lot less useful if it could only affect Java programs. – Kayaman May 12 '15 at 6:06
That's right. Robot only 'controls', you need to provide logic like 'If Frame minimized, click the minimized icon' to the Robot.
But this involves a whole set of new questions:
How do you know the Frame is minimized? (Sikuli)
What is the coordinate for the minimized icon? (Sikuli)
After you at least answered these two questions, you can control the Robot to have your Frame back and continue with your GUI Automation.
The answers are in the brackets.

Setting background image and greyed GlassPane in Java (Swing)

I'm struggling with two Java GUI things at the moment.
This is the situation: I'm designing a word game using Swing components. I have a main JFrame where everything is placed (my GUI class extends JFrame). There are two things I want to do:
1st: I would like to set an image as the background image of the main frame, it has to be displayed behind all components. i've searched around but haven't found a working solution. I tried making an extended BackGroundPanel class but when I create an instance of BackGroundPanel I have no idea how to make it the background of the frame... I also haven't find a good way to load in an image from an 'images' directory in my src folder...
2nd: when the program starts the user is greeted with an undecorated JDialog, the main frame needs to be disabled, which I figured out, but I would also like to make it a bit darker. I believe it should be possible with the GlassPane, but I have no idea how to set the GlassPane to cover the panel with one color...
Help will be much appreciated, I don't think I have any helpful code to share, but I think the situation explained above gives a general idea? I would just like someone to get me on track with this so I can further work this out! Thanks!
My Main class extends JFrame and it has a BorderLayout.
Add your BorderLayout to a JPanel having, e.g. GridLayout().
This AnimationTest illustrates painting a background image behind components.
This Translucent example illustrates using an AlphaComposite; see also this AlphaTest.
Well for your first question, you can use a label and set the icon of it:
JLabel lblimage = new JLabel("");
lblimage.setIcon(new ImageIcon(Main.class.getResource("/img/background.png")));
lblimage.setBounds(0, 0, 794, 711); //size of frame
contentPane.add(lblimage); //bottom
contentPane.add(component1); //middle low
contentPane.add(component2); //middle top
contentPane.add(component3); //top
as for your second question.. you could possibly do the same thing, just use an image with a solid color and lower the transparency, and place on top of your other components (not sure on this solution though).

Metal LAF JScrollPane rendering bug?

Having played around with the JScrollPane class for a couple of days, I've come across a very strange rendering problem regarding the horizontal JScrollBar compnent. When using these components within the default swing "Metal" look-and-feel, the center gripper pattern of the horizontal scrollbar appears to render incorrectly at specific content/viewport dimensions.
The code below opens a simple JFrame window with an embedded JScrollPane component, which appears to exhibit strange rendering behaviour as the horizontal scrollbar is dragged towards its rightmost extemity. As the rendering of the horizontal scrollbar gripper appears to be dependent upon the size of the content/viewport, this code opens the parent JFrame with an explicit dimension of 1402x800. Varying dimensions appear to have the same effect, including a maximized window at a 1440x900 resolution, and the problem tends to present itself more readily in a non-composited desktop environment (i.e. Windows XP or Vista/7 running a basic/classic theme).
public class Main
{
public static void main(String[] args)
{
ScrollbarTest application = new ScrollbarTest();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public class ScrollbarTest extends JFrame
{
public ScrollbarTest()
{
super("Scrollbar Test");
Container container = getContentPane();
JScrollPane scrollPane =
new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
JPanel contentPanel = new JPanel();
contentPanel.setPreferredSize(new Dimension(8000, 8000));
scrollPane.getViewport().add(contentPanel);
container.add(scrollPane);
setSize(1402,800);
setVisible(true);
}
}
As I am prohibited from uploading images directly to this forum, I have placed an image here depicting the anomaly that I'm currently experiencing. As you can see, the center gripper feature is not rendered correctly as I drag the horizontal scrollbar toward its right extremity. Please note that this does not appear to happen at all window sizes, but the initial JFrame dimension of 1402x800 certainly does the trick on my system. To be perfectly honest, this problem was not apparent until I moved from a 1280x800 to 1440x900 screen.
Any comments regarding the reproducibility and/or cause of this anomaly would be gratefully received.
Best regards, Lee.
Thank you all for taking the time to read this post. As we are not professional programmers, we had to seek advice in order to ensure that we were using the java API correctly.
We asked the guys at Sun to take a look at our problem, and this does appear to be a bug with the swing "Metal" look-and-feel. Please see below for the relevant correspondence.
Dear Java Developer,
Thank you for reporting this issue.
We have determined that this report is
a new bug and entered the bug into our
internal bug tracking system under Bug
Id: 7017935.
You can monitor this bug on the Java
Bug Database at
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7017935.
It may take a day or two before your
bug shows up in this external
database. If you are a member of the
Sun Developer Network (SDN), there are
two additional options once the bug is
visible.
Voting for the bug Click http://bugs.sun.com/bugdatabase/addVote.do?bug_id=7017935.
Adding the report to your Bug Watch list. You will receive an email
notification when this bug is updated.
Click
"http://bugs.sun.com/bugdatabase/addBugWatch.do?bug_id=7017935".
The Sun Developer Network
(http://developers.sun.com) is a free
service that Sun offers. To join,
visit
"https://softwarereg.sun.com/registration/developer/en_US/new_user".
Regards, Java Developer Support
Best regards, Lee.

Netbeans IDE 6.91 "center horizontally" not clickable

i am decent with java programming, but very new to GUI development. i wanted to make a console blackjack game i made years ago into one where people can play via a GUI i build using netbeans. i think that without a GUI, most people won't take the game seriously when i add it to my working portfolio
i created a JFRAME with the size set to 1000X700 pixels and on top of that is a JPanel with a background of dark green to simulate a blackjack table.
on top of the the dark green JPanel I have a small 60X93 JLabel with the icon set to be the back of a playing card. this represents the dealer and i wanted to CENTER it horizontally and vertically on top of the JPanel on which it rests.
however, in the netbeans tool bar for the particular GUI the "center horizontally" and "center vertically" options are greyed out and not clickable even when i select the JLabel which is the dealer. i even tried shift clicking to select both the JLabel AND the JPanel on which it rests but still the "center horizontally" and "center vertically" options are greyed out.
can someone please help me or offer guidance please? thank you... i have spent 2 days googling and i don't understand how others have not run into this same problem.
Interesting question. I've been working with NetBeans for years, and to be honest I've never even noticed those icons before until you just pointed them out. I'm unable to make them do anything either.
However, if you're new to GUI development in Java... you should read about layout managers, and spend some time with the GridBagLayout tutorial. GridBagLayout is by far the most popular layout manager in Swing development. You could get by using it exclusively if you wanted, as there are really only a handful of real-word situations in which it makes more sense to use another layout manager.
For your immediate purposes: In your Inspector view, right-click on the JPanel and select "Set Layout -> Grid Bag Layout". You'll now see your layout manager in the Inspector tree view right below your JPanel. Right-click on it and select "Customize". A window will pop-up, and there you can click on any component you're interested in and adjust all kinds of settings (e.g. margins, padding, etc). The setting in which you are interested is "Anchor", and the value you want is "Center". With your JLabel selected, you can adjust this setting either from the pull-down menu at the top-left... or graphically at the top-bottom.
One way or the other, if you're going to do any kind of Java GUI development beyond the most trivial of "Hello World" examples... you're going to be using GridBagLayout very soon. So you might as well dive in!
Let me provide some explanation about the tool button options "Center Horizontally" and "Center Vertically"
All the six toolbar buttons provided on the Matisse Designer are for alignment of the components related to each other. Those buttons only get activated when you select more that one component on the designer.
When we select two or more components on the designer window, may it be JPanel or JFrame, and click the "Center Horizontally" button all the selected controls (components) are aligned one below the other such that the center points of all the components are in one vertical line. That means they are moved in the horizontal direction to make them align exactly one below the other.
The "Center Vertically" button does this alignment in the vertical direction. So to answer your question the tools you are using for centering a component in JFrame are incorrect tools. They are for aligning components relatively to each other and not the container.
If you select a JPanel and a component inside the JPanel the tool buttons get disabled. The alignment setting buttons are available only when components are selected in the same container, in other words the components who are under same container.
To arrange a component in the center of the JFrame you may have to add some custom code or use some other layout manager other that Group Layout which is used by default by the designer.
with regards
Tushar Joshi, Nagpur

Categories

Resources