I'm currently working on building my first app. :)
I've now coded several Forms, each in an own class. Now, I want to implement the navigation from one Form to another, this is pretty straight forward since there is always only one "next" Form for every Form currently.
So i tried to do this by adding a "nextForm" Form to every Class and I want nextForm.show() every time the "next" Button is pressed. I tried it this way:
login = new Button("Login");
login.setUIID("nxtButtons");
login.addActionListener((e) ->
nextForm.show()
);
So, when i actually click the button, nothing happens.
Is the way I try to code this a good way? This is the first time Im heading into GUI building and I don't have experience here yet. Maybe one of you guys could help me here :)
Thank you very much
Kind regards,
Max
I'm assuming nextForm is null and you should see the null pointer exception in the console somewhere.
If not nextForm might be pointing at the current form which will do nothing. You can place a break point on that line in the debugger and see that the break point is reached then inspect the values of the variables.
Related
Simplifying, I have this structure
Form {
tab=Container(BoxLayout.y());
other stuff
}
The Form is not scrollable (and it is not supposed to be), tab is.
At some point I want to redraw the Form to keep it up to date with some new info added, and I do that creating a new one and showing it.
But I want to scroll down the Container tab to its predecessor's Y-coordinate.
I can easily save the Y coordinate in a static variable using
scrolledToY=tab.getScrollY();
But I can't find a way to set it back when I create the new form.
setScrollY seems to be protected, and indeed if I try to run the program using it, I get an error
error: setScrollY(int) has protected access in Component
tab.setScrollY(scrolledToY);
What is the correct function to use, instead?
Thanks.
You can use scrollRectToVisible().
FYI you can just modify the container and call revalidate to update the UI. This will prevent a nasty refresh problem you might experience. Also check out InfiniteContainer which might be what you're really looking for.
My idea is to create a kind of growing form. Now the question is: What is the best way to do this? I haven't found a library, yet. On the picture below, you can see how I thought it to be. It should go to the next step after each input and an EditText field should appear. Any advice on existing libraries or tips on which UI component should be used to realized would be appreciated. Thanks for the help!
you have plenty approach but the one i prefer to use:
make your list, then for each index assign its next EditText. by default make your all EditTexts (except first one) disabled. then add a listener each index to observe its text. as soon as it was filled tell that listener to enable its next EditText.
maybe its not so efficient but its simple and makes code more readable. and also you can extend that easily if you just implement two first indexes because the rest is just the same.
Doing it with the Robot class doesnt seem to work for me, unless there is a way without moving the cursor.
So what i need is a way to get the Component of another program (by creating a new MouseEvent) or just another way to use the Robot class.
Thanks already.
Use MouseInfo.getPointerInfo().getLocation() to get the mouse position right before you move it, then move it (and do whatever you'd like), and then return the mouse to its previous location.
The alternative is fairly complicated, and even more complicated if it's not a Java program - you'd need to provide much more information about that program, and your odds of getting a clean answer would be slim.
I am new to Java and I am working on a project where depending on number of files in a directory,
buttons will be created respectively. Each button will have a customized right click context menu.
How can I achieve this or is this feasible?
I just want to know the approach to do this.
The approach that you may try:
While you iterate your directory/file list (or other process that will determine the button creation), you can generate (create an instance of) a new button (JButton), I assume you know how to use new, and put it on your form / panel.
However, most of the time, layout would become an annoying issue here.
Thus, you may try to use MigLayout to handle this.
It will help you a lot in putting your stuffs in a tidy and convenient way.
Try this approach and when you have a specific coding-part question, you can try to search the existing solution in SO (StackOverflow) or if it doesn't exist, you can ask that specific code-related question.
Hope it helps.
I have an idea for my application, but I don't how to go about implementing it. Basically, I have a chat application, but you're able to tell the application whether it's a happy or sad message. I drew it out to hopefully make it easier for you to understand. Can anyone provide me with any insight on creating this kind of effect?
Step one (Hidden):
Step two (User clicks face):
Step three (user clicks face and it disappears):
Try this library.
Tutorial here - http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/
Library here - https://github.com/lorensiuswlt/NewQuickAction
Use QuickActionController. Find the source of the Control at https://github.com/lorensiuswlt/NewQuickAction.
You just need to shift the position of display towards the right at quickaction UI class. Your requirement will be met.