I want to simulate basic input for a swing application. The whole thing runs headless and doesn't even have a JFrame. I just render all components from the JPanel using the draw() method on a Image (If you want to know why: The Image gets rendered on minecraft maps where users then should be able to interact). I want to execute click or scroll actions on the panel like it would come from regular user.
I know that I can simulate a Button click using doClick() but this doesn't work for components like checkboxes. I also tried using dispatchEvent() but that didn't fire the animations or on some components even threw a HeadlessException.
Related
I‘m currently trying to render and use JComponents and it’s ancestors in a Custom Java Canvas. Right now, I‘m trying to create a Menu which should be clickable and it displays just fine inside my canvas when drawn with JComponent.draw(g). But the last piece I‘m trying to solve is that it should also react to the mouse-events the canvas generates (like hoovering over a JButton, clicking a JButton, etc etc). I only found listeners for events generated by the component…
So, is there any way I can tell a JComponent to not use its mouse events but instead pass through the events from somewhere else?
I'm currently developing the menu of my application and I would like to know what's the proper way of coding a "stage based menu". What I mean by stage based menu is that, user clicks a button, the entire interface changes to the next "stage". Here are the pictures I designed in Photoshop in order to explain my idea:
First picture would be the first stage and the second picture the second.
Each round looking thing is a JButton
So far I got the main menu (fist picture) made on eclipse using WindowBuilder, made it as a JPanel and then I instantiate it on the window class.
My idea was to have an event listener listen for clicks on each button and then once the even is triggered, have the JPanel variable on the frame change to the next "stage". So I was wondering if this is actually the proper way of doing this or are there any better ways?
You could use a Card Layout to make it easy to swap panels.
Check out the section from the Swing tutorial on How to Use Card Layout for more information and examples.
I have JFrame, that is setUndecorated(true) and inside it's content pane there is a LwjglCanvas a libgdx application rendering it's things.
I need at some point, do setUndecorated(false). But is seems to be impossible.
the decorated state cannot be changed once JFrame has been displayed, the only way to do it is to either create new JFrame, or dispose the existing one, and pack it back. Both solutions are terrible for me, because both will eventually notify LwjglCanvas to stop, and once stopped it cannot be started again.
I tried overwriting it's stop method, but it still get's messed up somehow.
Why do I need this?
I am trying to make a loading splash screen for libGDX desktop app, with a progress bar in it, that should display progress of my desktop app loading it's resources in opengl context. Splash screen has to be undecorated window, and when all loaded app itself should show, maximized and decorated.
Approaches that do not work:
Use one JFrame, and switch between decorated modes.
Try to move Lwjgl canvas from one JFrame to another
Use 2 separate Lwjgl canvases (cannot be done, because only one Al
context can be inited at a time)
How do I do this?
I need to make a Java desktop application for a client and the last time I did Java it was 2 years ago and a little odd.
My main query is regarding navigation between GUI.
In the past, I would just create a new JForm (JFrame maybe?) whenever a button was pressed and a new GUI form/window would open up.
This time, I'd like the GUI to be inside one JForm/JFrame with just the inner content changing, how most applications look when you press a button.
I assume this is done by putting all of my GUI elements in JPanels, and deleting/creating them when buttons are pressed on the same JForm?
If not how do I do it properly?
I'll also be using Netbeans GUI editor, if anyone has a better alternative for a Java GUI builder/IDE, let me know.
Thanks!
The simplest approach would be to use a CardLayout
This will allow you to add multiple components to the UI and control which one is actively visible
Another approach could be to create menus and menuItem and having multiple JFrames now you can get the same JFrame to be displayed whenever you click the same menuItme button. This way You can minimize the creation of JFrames.
I have been playing around with trying to get a menu screen for my game. I have only been able to figure out how to paint a new Screen on top of an existing one; meaning that the actual game is still running behind the title screen. I don't need actual code but just a description of how I would go about this.
One way to display a menu would by by using a JDialog outside of your main application window. Take a look at the How to Make Dialogs tutorial for more information.
Another possibility would be to use JInternalFrame for your game and menu so they can be wrapped in a larger application frame. These are explained nicely in How to Use Internal Frames