Maintaining PowerPoint in full screen while cliking in JFrame - java

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.

Related

Java transparent JPanel (allwaysOnTop) triggers Taskbar

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 :)

Identifying monitor applet is running on, in a multi-monitor system

I have Applet with a button running in a browser which when the button is clicked opens a JFrame. I would like to set the JFrame location to be the centre of the screen of whichever monitor the browser was running in. So if they only have one monitor the JFrame will open at the centre of this screen. If they have two monitors and the browser is in the left monitor clicking the button would open the JFrame at the centre of the left monitor. If the browser is in the right monitor display then clicking the button would cause the JFrame to open in the centre of the right monitor's display.
Currently I am using:-
Toolkit.getDefaultToolkit() to get a Toolkit object and then calling Toolkit.getScreenSize() to get the screen size and then working out the centre position from that. This is always based on the left monitor regardless of where the browser is.
Also, I know this could be further complicated if a user happened to have a different resolution between their monitors.
Get the GraphicsConfiguration of the JApplet and then pass that to the constructor of your JFrame. You would also use that GraphicsConfiguration to get a bounding rectangle for centering.
GraphicsDevice will give you info on all screen devices.
It's designed to handle the exact scenario that you need, just take a look at the sample code.
For centering one can normally use JFrame.setLocationRelativeTo(null). Maybe it centers on the default screen? What if the argument is the applet?

Java Applet: Create a Frame to choose a screen area

I want to create a applet which alows the user to select an area on the users screen.
The overlay I want to create should be the same as screenr.com uses it.
http://www.screenr.com/record
// Edit
What I want to setup is a applet which allows me to create screenshots from a area.
At the moment I create a new frame with the applet. This frame is transparent and contains a panel which can be dragged and resized. This panel is also transparent but it has borders.
So more or less everything works right.
Taking screenshots works well, uploading them too.
My problem now is, that the user cant click anything on his screen because my frame overlays the whole screen.

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

How to disable the minimize button in JFrame?

Can I disable the minimize button in JFrame?
I have already tried setUndecorated() and setResizable() but both did not work.
I'm trying to add images to a panel at a random location (which works) but when the JFrame is minimized by clicking at the minimize button (not when frame minimizes by clicking the background window) images assemble at the top in a row.
Can someone help?
Thanks!
If you also want to disable the maximize button then you can use a JDialog instead of a JFrame... as far as I know you cannot disable the minimize button in a JFrame. JDialog only has a close button. Hope this helps
i m trying to add imags to a panel at
a random location which i m able to
do) bt wen frame is minimized by
clicking at the minimize button (not
wen frame minimizes by clicking at the
background window) images assemble at
the top in a row.
Well, it sounds like you are adding labels to a panel and using the setLocation() method to position the labels.
The problem is that by default a JPanel uses a FlowLayout so whenever you do anything to the frame like minimize, maximize, iconify or resize the frame the layout manger is invoked and the labels are arranged according the the rules of the layout manager.
If your requirement is to have random positioning, then you need to use a "null layout".
Read the section from the Swing tutorial that explains how Absolute Positioning works for more information and a working example.
Use JDialog instead of JFrame it has only the Close button on the top.

Categories

Resources