I am trying to create JCombobox with multiple selection by holding ctrl key.
i have created Jcombobox for multiple selection by overinding ListCellRenderer.
it is working fine on selecting one by one .
but i required to select multiple using ctrl or shift key any way to achieve this.
Related
I have a registration panel where if student, instructor, and course administrator can register so if student is selected it should show something like this when Student is selected:
and should show like this if other two are selected like this when any of other two are selected:
I tried using if condition on the selected item in where I have added those text fields but it seems it only works at the beginning of the program when I run it on the basis of what is pre-selected and does not change when I select other items in JComboBox. Is there a solution to this?
You can achieve this in different ways. One of such ways is to use Action Listeners. A JComboBox object generates an action event when a selection is made (see Handling Events on a Combo Box).
In your case, you need to trigger an event based on the selection made in a combo box. This action should change the visibility of components in your panel, which are simply changing the visible attribute from true to false (or vice versa) depending on the selection made.
I need to select appropriate option from the popup window. Unfortunately, it is not the popup displayed by the web page, so I cannot use Selenium framework for that purpose.
As I checked, it is possible to navigate to different option by pressing arrow keys. Thus keyPress and keyRelease​ from Java AWT Robot should work for me perfectly to select option and confirm the selection by pressing Enter key.
Unfortunately, I do not see a method to read currently selected item text. Without that I cannot find appropriate option. Is it possible to read item label using Java AWT Robot?
If the target application is another java application, then you should be able to get a reference to the component hierarchy and traverse it until you find the text field & label in question.
Assuming it's not a java application, then I don't believe it's possible to do this - at least directly. Robot just provides mouse / keyboard input, but you could use it combined with other classes in the toolkit to at least partially solve your problem.
Use the Robot methods keyPress & keyRelease to input CTRL-A. Then CTRL-C.
Once the text is in the clipboard, you could read it using Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor)
You might be able to use the same approach for a text label, assuming it is selectable.
This question is talking about using java.awt.Robot to alter text in another program (MS excel), but it might provide you some additional ideas for tackling the problem:
How can I select text in another application with java.awt.robot (example: shift+home)
I have a Swing based application containing a JTable. Now I would like to allow each row to be updated or deleted, using a unique row ID. So I want to add an update and delete button to each row, which have the capability to support an ActionListener. However, I have no idea how to do this using NetBeans.
To display a button in a column you need to create:
a custom renderer to display the JButton
a custom editor to respond to the mouse click
Read the section from the Swing tutorial on How to Use Tables. The section on:
Using Custom Renders will explain the basics of using a renderer
Using Other Editors will explain the basics of using an editor
Working example are provided in the tutorial that you can download.
You can check out Table Button Column for one approach.
The code uses a single class to implement the custom renderer and editor that you will need for the column to display your text as a button.
I am attempting to use a JFileChooser to select multiple files. I know I can setMultiSelectionEnabled(true) but this selects all the files between the first file clicked and the second. Is there a way to make it only select the files that are clicked? I am looking for something similar to the MULTIPLE_INTERVAL_SELECTION in JList.
You can do so by holding Control (Ctrl) button while clicking the selections. The selection behaviour is standard behaviour and cannot be controlled programmatically.
I am new to the java language and I want to set tab order in JTable in java swing. How can we set tab order in java swing?
I assume you mean the "FocusTraversalPolicy", not sure if that is easy to handle inside of a JTable, however here is the relevant article from Sun/Oracle: http://download.oracle.com/javase/tutorial/uiswing/misc/focus.html
http://compgroups.net/comp.lang.java.gui/Custom-Tab-order-within-a-JTable
You need to write a custom Action that does tabbing the way you want. Read up on Key Bindings to find out how to replace an existing Action.
Or for an example that reuses the existing Action to only tab to cells that are editable you can check out Table Tabbing.