Select multiple rows on a JTable
Hi!
Given: JTable, multiple selection allowed
Wanted: a way to be able to set multiple non-continuous rows selected
eg. on a JTable with 5 rows,
I want to set rows 1, 3 and 5 selected
Anyone?
Stoffel.
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTE
VAL_SELECTION);
select rows using <ctrl> and/or <shift>Or if you want to set programaticly use this methods, see the api
for explanation.
table.changeSelecton(int row, int column, boolean toogle, boolean extend);
table.addRowSelection(int index0, int index1);
table.addColumnSelectionInterval(int index0, int index1)
...
Similar Messages
-
How can select Multiple Rows in a Jtable
Dear Forum
i am working on jclient\swing.
I want to select More than one row at a time from a table
I am trying the following code at INIT but it is not working.
jTable1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
Please suggest me for the same.
ThankxGirdhar,
I tried with JDeveloper 9.0.3 and it worked.
Either you are using another JDeveloper version, or you need to specify what you mean with "is not working".
Frank -
Selecting multiple rows in JTable
Hi
I wonder if it is possible to select multiple rows in a JTable. I have written the following:
table.setRowSelectionAllowed(true);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);However, when I select a second row, my first selected row unselects. I have to shift-click manually to select both rows. Is there a way around this (ie. without the shift-click part)?Well I have done that without finding anything... can you provide a link?
-
Multiple selection of row in a jtable
Hello All,
I am working with this jtable 'tblSearch'. The application requirement is that the user should have the ability to select multiple rows using the control key. I am using the bold part of the code to color the selected row light gray. Can you someone help me to select multiple rows by holding the control key down.
public void PopulateAS400(){
cmbView.hidePopup();
setCursor(hourglassCursor);
int scrPos = scpSearch.getHorizontalScrollBar().getValue();
oapprovalSQL = SQLFactory.createOrderApprovalSql();
Vector FreightList = oapprovalSQL.getData(getAs400SearchString(), getOrderby(), AS400, AS400Overide.length, searchItems, rdoMatchAny.isSelected());
columnNames = (Vector)FreightList.get(1);
data = (Vector)FreightList.get(0);
model = new DefaultTableModel(data,columnNames) {
public Object getValueAt(int row, int col) {
return super.getValueAt(row,col);
public boolean isCellEditable(int row, int col) {
if (row == 0){
getTblSearch().setColumnSelectionAllowed(true);
return true;
getTblSearch().setColumnSelectionAllowed(false);
return false;
public Class getColumnClass(int c) {
if(c == 5 || c == 9){
return BigDecimal.class;
}else{
return String.class;
JTable tmp = new JTable(model)
private final KeyStroke tabKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
private final KeyStroke shiftTabKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB,KeyEvent.SHIFT_DOWN_MASK);
public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
AWTEvent currentEvent = EventQueue.getCurrentEvent();
if(currentEvent instanceof KeyEvent)
KeyEvent ke = (KeyEvent)currentEvent;
if(ke.getSource()!=this)
return;
if (KeyStroke.getKeyStrokeForEvent(ke).equals(tabKeyStroke))
if (rowIndex > 0)
rowIndex = 0;
columnIndex = 0;
toggle = false;
extend = false;
getTblSearch().setColumnSelectionAllowed(true);
else if (KeyStroke.getKeyStrokeForEvent(ke).equals(shiftTabKeyStroke))
if (rowIndex > 0)
rowIndex = 0;
columnIndex = getTblSearch().getColumnCount()-1;
toggle = false;
extend = false;
getTblSearch().setColumnSelectionAllowed(true);
else if (columnIndex == getTblSearch().getColumnCount()-1)
rowIndex = 0;
columnIndex = getTblSearch().getColumnCount()-1;
toggle = false;
extend = false;
getTblSearch().setColumnSelectionAllowed(true);
super.changeSelection(rowIndex, columnIndex, toggle, extend);
public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColumnIndex)
Component c = super.prepareRenderer(renderer, rowIndex, vColumnIndex);
if ((vColumnIndex == 7) && (rowIndex > 0))
if ((model.getValueAt(rowIndex,7) != null) && (model.getValueAt(rowIndex,7).toString().equalsIgnoreCase("NMI")))
c.setBackground(Color.red);
else if ((model.getValueAt(rowIndex,7) != null) && (model.getValueAt(rowIndex,7).toString().equalsIgnoreCase("NMI ANSWERED")))
c.setBackground(Color.green);
else
c.setBackground(Color.white);
else
c.setBackground(Color.white);
**if (isRowSelected(rowIndex) && (rowIndex > 0)){**
**((JComponent)c).setBackground(Color.LIGHT_GRAY);**
if (rowIndex == 0 && isCellSelected(rowIndex, vColumnIndex)) {
c.setBackground(lightBlue);
return c;
setTblSearch(tmp);
getTblSearch().setAutoscrolls(true);
getTblSearch().setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
getTblSearch().setAutoCreateColumnsFromModel(false);
getTblSearch().setColumnSelectionAllowed(false);
getTblSearch().setRowSelectionAllowed(true);
getTblSearch().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
JTableHeader header8 = getTblSearch().getTableHeader();
ColumnHeaderListener colH8 = new ColumnHeaderListener();
colH8.setCallFrom("OrderApproval");
colH8.setOapproval(this);
header8.addMouseListener(colH8);
header8.setReorderingAllowed(false);
header8.setResizingAllowed(false);
getTblSearch().getColumn("Co #").setCellEditor(asCompCell);
getTblSearch().getColumn("Reg").setCellEditor(asRegCell);
getTblSearch().getColumn("Rep #").setCellEditor(asRepCell);
packColumns(getTblSearch(), 1);
getTblSearch().getColumnModel().getColumn(6).setPreferredWidth(240);
for(int i=0; i<searchEntries8.length; i++) {
getTblSearch().setValueAt(searchEntries8,0,i);
((GenericTextEditor)getTblSearch().getCellEditor(0,i)).setCellEditorValue(searchEntries8[i]);
scpSearch.add(new PopupContainer());
popupMenu = new JPopupMenu();
JMenuItem printFinalOrderMenu = new JMenuItem(PRINTFINALORDER_CMD);
printFinalOrderMenu.addActionListener(new PrintFinalOrderMenuListener());
popupMenu.add(printFinalOrderMenu);
MouseListener popupListener = new PopupListener();
getTblSearch().addMouseListener(popupListener);
scpSearch.setViewportView(getTblSearch());
scpSearch.getHorizontalScrollBar().setValue(scrPos);
setCursor(normalCursor);
Thank you all for your time n help.
Edited by: anjan_dev on Jan 29, 2008 2:14 PM
Edited by: anjan_dev on Jan 29, 2008 2:15 PM
Edited by: anjan_dev on Jan 29, 2008 2:16 PMThe issue is when I have one row already selected and then when I click on another row while holding the control key down. Our application needs an user to be able to select multiple rows at the same time.That is the default behaviour. I have no idea why it doesn't work for you.
Get rid of all your custom KeyEvent logic and try it again.
If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
http://homepage1.nifty.com/algafield/sscce.html
Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
http://forum.java.sun.com/help.jspa?sec=formatting -
Delete multiple rows in a JTable ADF Swing.
hi guys,
Would anyone know tell me how do I delete multiple rows in a JTable ADF Swing?
JDeveloper.Hi,
I would configure the table for multi row selection. Then get the selected row index, access the iterator in the PageDef file (through the panelBinding reference you have in ADF Swing) and then iterate over the selected row indexes, make an index to become the current row and call remove() on it
Frank -
How to select multiple rows from List Of Values
Hello,
I use ADF 11g to create my list of values (LOV). I want to select multiple rows from it. but i can't.
so how i can select many rows to set them in my adf table.
Thank in advanceHi,
LOV is map to an attribute in the viewObject so it will return only one value or more values from selected row. You can't select multiple rows from LOV.
But you can do this by using popup which you can select multiple rows and insert the selected rows to another table.
This blog post explain how to achieve this :
http://husaindalal.blogspot.com/2009/11/search-from-popup-and-add-to-new-table.html#comments
Sameh Nassar -
How to select multiple row in ALV report
Hi friends,
1. How to select multiple row in ALV report
( How to set tab in ALV report and want to select multiple line.)
Thanking you.
SubashHi Sahoo,
If you are using the class CL_GUI_ALV_GRID. In methods SET_TABLE_FOR_FIRST_DISPLAY.
in layout structure you will find field SEL_MODE
pass :
LS_LAYOUT-SEL_MODE = 'A'.
In PAI.
CALL METHOD GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = T_ROWS
ET_ROW_NO = T_ROWID.
Hope these will solve your problem.
Regards,
Kumar M. -
Select Multiple Rows in a Table without CTRL
Expecting the user to press "Ctrl" when selecting multple rows is very unfriendly and unintuitive. We'd like the row selection to work as in ALV where you just select multiple rows by clicking on them.
We've set the tables rowSelectable to true and selectionMode to 'multi' but we still cannot select multiple rows without the CTRL hotkey.
This issue apparently [arose before|About selection in the table] but wasn't resolved.
System Details
SAP_ABA 701 0006 SAPKA70106
SAP_BASIS 701 0006 SAPKB70106
SAP_AP 700 0019 SAPKNA7019Hello Marc,
you need to call IF_WD_CONTEXT_NODE->set_selected(index = lv_index) sorry for the typo in my previous comment.
by calling IF_WD_CONTEXT_NODE->set_selected method wont remove the lead selection.
to unselect the records, you can call the same method by passing the FLAG value as abap_false.
so for your usecase the logic will be like this in the ON_SELECT event handler
1. get the index of the new_lead_selection
2. check whether this is already seleted in the context node by calling IF_WD_CONTEXT_NODE->IS_selected
3. if already selected then call IF_WD_CONTEXT_NODE->set_selected( flag = abap_false index = lv_index)
if not selected then call IF_WD_CONTEXT_NODE->set_selected( index = lv_index )
Hope this solved your problem.
BR, Saravanan
Edited by: Saraa_n on Jul 6, 2011 11:52 AM -
Selecting multiple rows in a table
Hi All,
I have one problem with selecting multiple rows in a table.I tried with setting table property-selectionMode as Multi, but i dinn't get the solution.
please provide me solution for this.
Thanks & Regards,
Sreelakshmi.HI
Int leadSelection = wdcontext.nodemodelnode.getLeadSelection();
for(int i=0;i<wdcontext.nodeModelNode.size;i++)
if(wdcontext.nodeModelNode.isMultiselected(i) || leadSelection ==i)
String name = wdcontext.nodemodelnode.getnameelementatindex(i).getName();
String address = wdcontext.nodemodelnode.getaddresselementatindex(i).getAddress();
String age = wdcontext.nodemodelnode.getAgeelementatindex(i).getAge();
Create a method for the Table Property onLeadSelect() where you can open a popup window
Create a value node and with attributes same as Table attributes and then set the values of the table
to the value node attributes.
Thanks -
Select multiple rows in a grid
Hi All,
I want to select multiple rows in a grid on click of a button, there is no checkbox there are multiple rows which need to be selected like we do on pressing shift key on the keyboard. Please suggest how can this be done.
thanks in advance.
Regards,
AnjuHi Anju,
You can check this link to solve your problem:
https://wiki.sdn.sap.com/wiki/display/Snippets/ALV%2bGrid%2bDisplay%2bwith%2bcheckbox%2bto%2bprocess%2bselected%2brecords%2bat%2bruntime
Hope it helps you.
Thanks & Regards,
Sarita Singh Rathour -
Select multiple row in a table that are not connected
I want to be able to select multiple rows, but want to be able to select rows that are not next to each other. They maybe have one or two rows between. Is there anyway to do this in a table?
ThanksSo do a lot of other people, but you can’t.
Tell Adobe here: https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
Bob -
Select multiple rows from dual table
Is it possible to select multiple rows from dual table using a single select statement.
i.e., i want the out put to be
column_name
1
2
3
4
Edited by: vidya.ramachandra on Dec 14, 2009 8:24 AMAside from the fact you're responding to an old thread...
1002424 wrote:
While using CONNECT BY, I see it always leave behind one row.
Suppose I have a condition based on which I have to generate constant rows like
SELECT 1 FROM DUAL WHERE ROWNUM < N;
Here if N = 0, still it gives out single row.... you are obviously doing something wrong in your code elsewhere, because that SQL statement does not always return a single row...
SQL> SELECT 1 FROM DUAL WHERE ROWNUM < 0;
no rows selected
SQL> -
Pressing cntrl+left mouse click doesn't select multiple rows.
Hi,
I've got this problem after i migrated my form from 6i to 10g.
In 6i version, cntrl+left mouse click used to work in order to select multiple rows on the screen. But, it's not working in 10g.
Instead, Shit + left mouse click is working to select multiple rows in 10g.
Please can someone help me out with this. I want cntrl + left mouse click to work.
Any help will be appreciated.
Regards
NavnitHi Pradeep,
Thanks for your reply.
Do you mean fmrweb.res file?
This is the content of my res file
9 : 0 : "Tab" : 1 : "Next Field"
9 : 1 : "Shift+Tab" : 2 : "Previous Field"
116 : 0 : "F5" : 3 : "Clear Field"
38 : 0 : "Up" : 6 : "Up"
40 : 0 : "Down" : 7 : "Down"
33 : 0 : "PageUp" : 12 : "Scroll Up"
34 : 0 : "PageDown" : 13 : "Scroll Down"
69 : 2 : "Ctrl+E" : 22 : "Edit"
10 : 0 : "Return" : 27 : "Return"
76 : 2 : "Ctrl+L" : 29 : "List of Values"
115 : 0 : "F4" : 32 : "Exit"
75 : 2 : "Ctrl+K" : 35 : "Show Keys"
83 : 2 : "Ctrl+S" : 36 : "Commit"
118 : 1 : "Shift+F7" : 61 : "Next Primary Key"
117 : 0 : "F6" : 62 : "Clear Record"
38 : 2 : "Ctrl+Up" : 63 : "Delete Record"
117 : 1 : "Shift+F6" : 64 : "Duplicate Record"
40 : 2 : "Ctrl+Down" : 65 : "Insert Record"
119 : 1 : "Shift+F8" : 66 : "Next Set of Records"
1005 : 0 : "Down" : 67 : "Next Record"
1004 : 0 : "Up" : 68 : "Previous Record"
118 : 0 : "F7" : 69 : "Clear Block"
66 : 2 : "Ctrl+B" : 70 : "Block Menu"
34 : 1 : "Shift+PageDown" : 71 : "Next Block"
33 : 1 : "Shift+PageUp" : 72 : "Previous Block"
116 : 1 : "Shift+F5" : 73 : "Duplicate Field"
119 : 0 : "F8" : 74 : "Clear Form"
122 : 0 : "F11" : 76 : "Enter Query"
122 : 2 : "Ctrl+F11" : 77 : "Execute Query"
69 : 3 : "Shift+Ctrl+E" : 78 : "Display Error"
80 : 2 : "Ctrl+P" : 79 : "Print"
123 : 0 : "F12" : 80 : "Count Query"
85 : 2 : "Ctrl+U" : 81 : "Update Record"
121 : 3 : "Shift+Ctrl+F10" : 82 : "Function 0"
112 : 3 : "Shift+Ctrl+F1" : 83 : "Function 1"
113 : 3 : "Shift+Ctrl+F2" : 84 : "Function 2"
114 : 3 : "Shift+Ctrl+F3" : 85 : "Function 3"
115 : 3 : "Shift+Ctrl+F4" : 86 : "Function 4"
116 : 3 : "Shift+Ctrl+F5" : 87 : "Function 5"
117 : 3 : "Shift+Ctrl+F6" : 88 : "Function 6"
118 : 3 : "Shift+Ctrl+F7" : 89 : "Function 7"
119 : 3 : "Shift+Ctrl+F8" : 90 : "Function 8"
120 : 3 : "Shift+Ctrl+F9" : 91 : "Function 9"
113 : 0 : "F2" : 95 : "List Tab Pages"
72 : 2 : "Ctrl+H" : 30 : "Help"
112 : 0 : "F1" : 30 : "Help"
I don't know what value should i enter for cntrl + left mouse click ?
Even for shift + left mouse click, row is not there but it's working.
Please tell if you know what row should i enter for cntrl + left mouse click in order for it to select mutliple rows?
Regards
Navnit -
How to select multiple row of table using check box?
hi,
i am having table on view having first field as checkbox. what i want, when i click on checkboxes in multiple rows, and i click on any button i need to use those content to next view...
my problem is if i select only one row , i can use onlead select property of table..but when i select multiple rows through check box how should i read contents of table....?
Plz solve it.
Thanks,
Saurin ShahHello Saurin,
You are right using LeadSelection you can select only 1 row at a time. You will have to make use of Selection for achieving this. First you will have to change the selection mode of the table to multiple & also change the selection property for the related context to 0..n . Please find a code extract which might help you. (However this facility is only available from SP 14.) The main part is using the set_selected method of if_wd_context_node.
data: node_zcourse_details type ref to if_wd_context_node,
node_course_assign type ref to if_wd_context_node,
elem_course_assign type ref to if_wd_context_element,
stru_course_assign type if_v_details=>element_course_assign ,
item_popin_selected like stru_course_assign-popin_selected.
" navigate from <CONTEXT> to <ZCOURSE_DETAILS> via lead selection
node_zcourse_details = wd_context->get_child_node( name = if_v_details=>wdctx_zcourse_details ).
" navigate from <ZCOURSE_DETAILS> to <COURSE_ASSIGN> via lead selection
node_course_assign = node_zcourse_details->get_child_node( name = if_v_details=>wdctx_course_assign ).
" @TODO handle not set lead selection
if ( node_course_assign is initial ).
exit.
endif.
data elem_set type wdr_context_element_set.
field-symbols <wa_elem> like line of elem_set.
elem_set = node_course_assign->get_elements( ).
loop at elem_set assigning <wa_elem>.
<wa_elem>->set_selected( TRUE OR FALSE ). " Supply either TRUE/FALSE in here
endloop. -
Selecting multiple rows in a block
In a multi record block, I would like to select multiple rows by double clicking on them. The backgroung color of all the selected rows should change to Blue.
If I change the color using set_item_property, the color of all the rows change. If I set using set_block_property, it changes only for the current row. when I go to the next record, the color is set back to normal. Using set_record_property on the status of the record can be set.
Can someone help me to achieve this?
Thanks in advanceI answered this in your other, duplicate, post.
Regards,
Robin Zimmermann
Forms Product Management
Maybe you are looking for
-
Can not see two fields in Crystal 2008 Developer explorer/designer view
I am currently developing crystal 2008 reports against the salesforce.com database using version 12.0.0.683 CR Developer Full version. I am using an updated driver that was provided in July or Aug 08 in order to view self referencing fields. The prob
-
Can we create .CIF file in PI 7.0
Hi experts, I have a requirement in which I have to convert the source xml file into target file in CIF format. So my target my file should be target.cif. I want to know whether we can handle this format in XI or not. Below is the example file in CIF
-
i'm trying to append some string to a file but it gives me error while compiling. here's my code: import java.io.FileOutputStream; import java.io.File; import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.awt.*; i
-
i wish to know whether the content of the file i saved is viewable? let's say i FileOutputStream something(eg. hello) in a file.txt. so can i view the content of file.txt ('hello')?
-
How to Install and Configure BRM Adapter in SOA
Hi All, We are Doing Customization for AIA 2.5 Comms PIP. We need a BRM Adapter is there any info how to install and configure BRM Adapter. Thanks, RR