Java Swing: I recently started learning Swing and I want to add several labels, one button, and three combo box INSIDE A Drop Down Pane! When the user clicks the drop down pane, you can see labels, textfields and comboboxes which will contain the values and when the users clicks drop down pane again, then all the textfields, labels etc are hidden. Is it possible and if yes then could you please help me out (code would be very much appreciated). If you did not understand the design then please visit emirates.com and click on 'Book a Flight'! I'll be trying to implement that type of design
If you want a multi-row data display object, and you want multiple interactable components on the row, don't use the wrong tool, a JComboBox, for this. Use a better tool: a JTable.
Related
I'm writing a GUI. In that GUI I have a dropdown box in which I can select different persons. Each person has a CardLayout Pane and in that Pane a table with information about themselves and things they own.
I have written a class called PanelTableItems(Person person).
On program start I use this class to create mutliple of these tables (one for each person in my program). And each CardLayout Pane has one of these tables. I have just implemented a ListSelectionListener to store the last selected row which I am using a private function to get the selected item from the table. However as I implemented this selection listener I tried with a print and for some reason it seems that if I have two persons in my program the selection listener made two prints even though the "second" table was not in view and therefore not selected.
Here is my question:
How do I make sure to only operate the table that is currently in "view" using the CardLayout? The second pane is hidden but it seems that all function calls to the first pane also manages to run on the second one as they are of the same type.
I could post a MCVE, but this is more of a theoretical/solution question than an actual coding question.
Thanks in advance.
On person selection, you could just switch visible panel with:
CardLayout cl = (CardLayout) cards.getLayout();
cl.show(cards, "idOfTheSelectedPersonPanel");
So, you should have registered those panels already in the layout each one with different id in regard to the person it represents.
Hidden (not visible) panels do not get any user input - if you see such behaving then your code does something wrong.
In ListSelectionListener you need to filter to process only events that something new is selected.
I suggest you to recheck the way you are adding the components to your cards you are maybe adding all tables to the same container witch makes only the last one visible, try adding each table to a JPanel or a JScrollPane.
I am attempting to create a simple java form using Swing. The idea basic idea is that the user will select 0 through 5 in a JComboBox. Then, via an ItemStateChanged listener, several panels will be dynamically added, each congaing 4 controls themselves. So if the user selects the number three, three panels are added each containing a textbox and a combo box. I would then like to send this information to a database. I don't want to have a bunch of nulls in my database caused by a one size fits all form. So if the user selects 3, 3new rows will be added to the database. Any help or insight would be appreciated.
Thank You for your time.
I think that you have look at CardLayout, tutorial shows example about switching betweens the JPanels from JComboBox'es events
I want a jTextField that shows suggestions in a popup as the user types (like google suggests). I want suggestions data to be fetched from a database table. I have been looking at SwingX and GlazedLists but I think they provide jComboBox autocomplete, and jTextField does not show a popup in these libraries.
I want to monitor user input and re-query the database after specific intervals.
Thanks.
I would keep looking into SwingX or GlazedLists, to avoid re-inventing the wheel. But if you are doing it yourself:
Add a KeyListener to the field and show a popup just below the text field whenever the user types. The popup could just be a menu with possible items or maybe even a JList. Make sure your database query can keep up with the typing or put the work on a separate thread.
I have a JTable displays the event accordingly, I want to do like when mouse over the table cell will pop out a small box show the event details. Something like tooltip how can i do that? is there any component in swing doing that?
Have a read about How to Use Tables: Specifying Tool Tips for Cells.
Use JToolTip and HTML. More info here:
http://java.sun.com/docs/books/tutorial/uiswing/components/html.html
I have a very simple Swing GUI with just a JTetxtArea. I am trying to programmatically select a part of text using:
textArea.select(startSelection,endSelection);
This work. However as soon as I add some other components to the GUI I do not see selection anymore
frame.getContentPane().add(button);
frame.getContentPane().add(textArea);
textArea.select(startSelection,endSelection);
I suspect that during layouting the gui, some event causes the text to be deselected. Am I right? And could anybody suggest a solution?
My goal is to have a program which displays a text, and allows the user to input start and end selection position, and a selection appears between these two position. Thank you.
Text selection only shows when the text component has focus.
Text components also support "highlighting" by using the getHighlighter().addHighlight() method. In this case the highlighting remains whether the component has focus or not.
If you need more help post your SSCCE that demonstrates the problem.
If what you really want is just a selection, not highlight (which behaves differently), you can use JTextComponent.getCaret().setSelectionVisible(true).