Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
If I am taking a large amount of input from a user lets say the favorite colour of a student in a classroom of 30 students.
I want the teacher to input each favorite colour. I dont want to ask the teacher for each name of the student in showDialogBox then search a file to show that the student exists then ask to input the colour.
Is there a way of displaying a Box which looks something like this
John-(blank space to enter txt eg.colour)
James-(blank space to enter colour)
Or something like that, or would there be a better more convienient way for the user to input the data.
Then what comes to mind is changing a colour for a student.
Any help in pointing in the right direction would be much appreciated.
I would use a JFrame/JPanel
Frame:
http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html
Panel:
http://docs.oracle.com/javase/7/docs/api/javax/swing/JPanel.html
Yes, there are many ways. Some of your many options are:
Create a custom JPanel based component that has a label to display the name and a text input box. Read the student names and dynamically add one of these components per student to your form.
Use a JTable that has a column for the name and an editable column for the color (see http://docs.oracle.com/javase/tutorial/uiswing/components/table.html for a tutorial on creating tables with editable input).
Iterate through student names and display a dialog box for each. Rather than having the teacher enter the names, display the names from the file and just have the teacher enter the color.
The first two options require you to build your own input window, which would likely be a JFrame based component. The last option lets you use JOptionPane without having to do any of your own interface coding.
You should try one of these ways, or maybe some other way that you think of, then if you are having a specific problem, come back here and ask.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I was looking for an answer how to let user add more text field depending on his request... As i guess it comes from some kind of list but how to earn similary to this below efect ? addable edit text
My target is to create some kind of a formula where user adds his ingredients and their amount, everything has it's own Type like chicken is a meat, potatoe is a vegetable etc.
I want to make it a part of a material design project so it should fits to it.
I dont request for a full code answer(what would be great anyway, i try to learn it in the best way), even a tip is significant for me.
Thx for help :)!
Depending on how many items can be added, a ListView or probably better a RecyclerView (better/easier for animations than ListView) might be ideal. However, if you only see a user having between 1 - 20ish ingredients an easy approach might be just to dynamically inflate items.
When the "Add" button is pressed, use LayoutInflater to inflate a new view which represents the ingredient and then add it to the parent. In your layout xml, add android:animateLayoutChanges="true" to your parent layout. Now, when the new ingredient is added it will do a nice insert animation. It will also create a nice animation when you remove a child from the parent.
This Android Developer Article might be helpful too.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
So I have an array of cards. These cards consist of numbers 0-51. Is there a way that I can write Java code that can look at the number and load up a specific image. I dont mind writing 52 if statemets but I would prefer not to. I also want to display some data like bets up on the screen. and such. (Even in dialog boxes). Just want to make this game look good. Variables I want to show in the GUI
/**
* Global variables include the money inside of the pot Each players money
* And the cards
*/
static int[] moneys;
static int userBet;
static int compBet;
static int pot;
static String userName;
// tells the ai what it did to adjust long term strategies V
static int[] aiInfo = {0, 0};
static int[] numberCards;
static int roundOfBets;
I just want it to look nice. Instead of System.out.println("tons of data goes here");
Is there good code. That allows a GUI that would have buttons and such. And would allow me to set a variable to a certain value when clicked.
Here is the set up I am looking for
I just want general code or a library. The interface should look like this______________________________________________________
Dialog Box Your Money =this |____________________________________pot=this_______
Computer has this much money|___________________________________________________ Community Cards pics______________________________________________ _ _____________
My cards pictures___________typing box for money___________Question(yes or no answer)
Are you familiar with Swing? Java has a whole library of components, known collectively as Swing, specifically aimed at making a GUI. Oracle's Swing tutorial is here.
Using Swing you can do just about anything you want, including making windows, dialog boxes, pop-up boxes, etc. You can add buttons, labels, images (like your card images, for example), and tons of other stuff to any window you want.
You don't say if you're already using an IDE (Integrated Development Environment) or not, but if you get into Swing I'd strongly recommend it. Many here will (rightly) tell you to code by hand as much as you can, but coding Swing objects by hand can get daunting. With an IDE you can "drag and drop" buttons and other components into your windows and the IDE will write the code for you. If you really want to learn Java, though, you'll have to go poking through that auto-generated code to make sure you understand what it's doing. Very soon, you'll likely run across something you don't understand. When that happens look it up. If you can't find a good answer come here and ask.
As for your array of cards, 52 if statements isn't going to be efficient or easy to maintain. You'd likely want to use some kind of loop to "find" the right card, then perform whatever action (display image, for example) you want.
EDIT: The NetBeans User Guide is here. It probably includes a lot of features you won't need to worry about right away, but if you want to know what NetBeans can really do, skim through it.
I should also point out that NetBeans is not the only IDE out there. For Java, Eclipse is the other major one I'm aware of. Once you get your feet wet it might be worth trying another IDE just to see which you like better.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm creating frame which asks user to enter his information. I want to notify user using labels or something else when he does not give required input. Like here is the screenshot when all fields are empty:
As when wrong input is entered and i move to the next text field text appears in red color below the text field. here is the screenshot:. i want to do this. Does anyone tell me how to do this..????
There are few ways to achieve this...
The first thing you need to do is valid the field...
You Could...
Use an InputVerifier which allows to validate a field when it loses focus as demonstrated here.
This method also allows you to determine if focus should be continue to the next field or remain with the current field.
You Could...
Use a FocusListener and valid the field when focus is lost. This is pretty much the same thing as the above suggestion, just know you have to do the work yourself
You Could...
Use a DocumentListener on text fields to monitor changes to the fields contents and perform real time validation of the field.
Next, you need to determine the best way to display the state...
You can use:
A LineBorder to change the field's border state. Be careful though, some look and feels won't like you doing this (looking at you MacOS). Take a look at How to use borders for more details
The tool tip API
setVisible to toggle the visibility of JLabels to display error messages, but to be honest, I might be tempted to use a full alpha color to hide the text and a full opaque color to show as this won't effect the layout
Ballon Tip
GridBagLayout would probably be my choice of layout manager, but you could also use compound layouts to make things eaiser
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i using netbean gui. i donno the code is it same or not. but atleast i had a rough idea on how to do it.
i had a Jtable, textfield and a Jbutton
i wan to enter something into textfield and after clicking the button, the textfield will draw the data from database and set it to the Jtable. everytime i key in something to text field, i wan the data to be appear in Jtable. is this possible?
i already try using jtable model. but i don't know how to create proper jtable model.
I Suggest you explore your netbeans IDE where UI designing is a piece of cake especially inserting jTextfield, jTable etc......using simple drag and drop.
(There's option to create a swing based java file by default where javax.swing.JFrame or similar classes are extended automatically. Insertion can be done via Design Tab.)
And about getting the functions to read from jTables and jTextfields. I suggest you to check the corresponding javadocs.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am working on a project where user faces 5 frames . Each frame contains the data to be filled . so when he completes the one frame and goes to next frame it has to confirm that the data is filled for that I want to use BreadCrumb(or progressbar).
so how to create a BreadCrumb(or progressbar) in java swings
I want to make similar to below image in java swings
I suggest that you
create 5 images to use as your breadcrumb images. Any basic image editing program can help you with this.
Put the 5 images in ImageIcons, and put the ImageIcons in either an array or an ArrayList<ImageIcon>.
Display the current Icon in a JLabel that is part of your GUI. You can easily set the JLabel's Icon via its setIcon(Icon icon) method.
I would strongly urge you not to use "5 frames" since that is an irksome user experience and is not what the user experiences when using a professional application.
Instead create 5 JPanels that handle each part of the process.
Swap these JPanels in and out of your GUI via a CardLayout-using JPanel, one that I assume will sit on top of the JLabel that displays your breadcrumb ImageIcons.
When you swap a JPanel view, you also swap an ImageIcon. This swapping will likely be done in the same method.
Remember that it is Java "Swing", not "swings". Good luck.