dropdown panel with java - java

I am currently working to create a GUI and encountered the following problem:
Similar to a JComboBox or JMenu i want to create a drop-down-panel with java, but i don't want to list a few JMenuItems or something similar. What I want to display is a new JPanel. You could compare it to the chatwindow in facebook.
Not eve Google could help me. All I could find was about JComboBox or JMenu.
So here is my question: Is there already a predefined class, that im just unable to find or do I have to make one for myself? If I have to create it, how do I do it?

To bring this to an "official" end:
You can actually add any Component to a JMenu. You are not restricted to only JMenuItems.
Thank you VGR for your comment

Related

How jdatechooser was made?

So I've got this program I'm building and I'm planning on making my own custom dropdown menu, cuz it'd be way cooler that way.
The way I've set about doing just that is to create a separate frame for that exact drop down menu. The problem? When the program woulf run and when I'd use the custom dropdown it'd essentially run a new instance of that dropDownFrame separate from the main program, which isn't how a dropdown menu should work.
So I've been wondering, how was jdatechooser made? It seems to me that it was custom made and they probably used existing java gui classes to create it.
I'm a noob so if I have any mistake in my terminolgy please forgive me seniors.
Hehehe tnx in advance

Creating a text adventure in Java

I am trying to create a text based adventure in Java I need help in combining a Scanner with JPanel so that the user can type into the panel directly rather than choosing from a list of options. Is there any way of doing this or would a dialogue be needed and if so is there a way of doing so within the JPanel?
For doing so, you need to add some components to your panel, such as, JtextField or JTextArea.
Then you have to add a action listener to your text field/area.
You can find a lot of advices with a simple google search.

Using CardLayout in NetBeans GUI Builder

I am using the NetBeans 7.2.1 GUI Builder. I could do all of this by hand. Instead, I am using my current project to learn how this tool works so that I can make an informed decision of when to use it in the futre (if at all).
Now with help of archived questions here, I have figured out how to change the LayoutManager to a CardLayout. I have also added three JPanels to the layout (although, there seems to be a bug...maybe a question about that later). The first JPanel displayed by the CardLayout will have two buttons. Each button will cause the CardLayout to display one of the other two JPanels. To do this, I found that I can use CardLayout#show(Container, String).
I need to know what the value of the String is for each JPanel. Doing some further research, I found that NetBeans generates a line of code such as
getContentPane().add(addCardsPanel, "card2");
So I can use "card2" to show addCardsPanel. It would be convenient to use a more applicable String. Will NetBeans allow me to set this identifying String to whatever value I wish? If so, how do I do it?
In the Navigator window select the panel you want.
In the Properties window scroll down to the Layout group. You'll see a Card Name property. Knock your self out ;)

Navigate between windows in a simple quiz app

I have to make a simple quiz application in JAVA and I have no idea on how to navigate between windows, for example, how to go to the next question or how to go back. I have a single question per window. Can you give me an idea on how to navigate? Should I use repaint() or a CardLayout or something else?
Thanks!
Yes CardLayout can be a good idea for this purpose, if you need some example take a look at the oracle how to.
If the quiz is multiple choice, you have other options: change the data that the questions (probably JRadioButtons) displays. Otherwise, I vote for a CardLayout. Also, if you want the user to be able to easily go back to other questions, you could display them all as JPanels in a GridLayout using JPanel held by a JScrollPane.

Java Dropdown Checklist

I understand how to make a multiple-select list box using JLists but I want to add JCheckBoxes to the list and make it dropdown like. The best visual representation I have found online is dropdown-check-list.
What would be the best way to accomplish the above?
I was thinking of a TableList. Any suggestions?
If you are using JList, then its as simple as changing the ListCellRenderer to return a JCheckbox component.
EDIT:
For JCombobox, you can use combobox.setRenderer(myListRenderer);
This code snippet may help you.
The basic idea is to handle actionPerformed or mouseClick events by yourself and keep states of the corresponding items (checked/unchecked) in your own data structure. You'll be able to use that data structure for rendering checkboxes in a dropdown

Categories

Resources