JTable and selected row
Hi,
I'm new to Java, I'm writing a simple application using Swing, I've almost finished, almost, becose I have a jTabbedPane on 1st pane some labels and text fields, and on the second one jTable, I have to do 2 things:
When row in JTable is selected, then the same user data should bevisible in JTabbedPane/Panel1 and if I select someon in panel1 then also the person in the jTable should be selected, what should I do? What's the function name? Please help.
http://java.sun.com/docs/books/tutorial/uiswing/events/eventsandcomponents.html
Similar Messages
-
Finding and selecting rows JTable
Hey all!
Im having a bit of trouble with my JTable, I have a JInternalFrame which holds a JTable and a "Find" button, once you press the Find button a seperate JFrame pops up and searches the JTable for the information entered, but it just gives a JOptionPane saying that it was found at row 'n'
What i want instead of the JOptionPane is for the JFrame to stay open (so you can Find Next) and for the row that has the information to be highlighted/selected
Any ideas on this would be great,
Thanks in advancewrite for a class `search` with constructor
search(myTable tab)
onClick event of the button pass table object to the search constructor
public void actionPerformed(ActionEvent e)
search s=new search(mainTable);//<--Your table object
}now whatever you do for that object you can handle the main
table object.
use this to select cell
table.changeSelection(row,col,false,false);
In class search add passed table in the frame -
How to find out if JTable's selected row is visible?
Hello there,
Given:
a JTable is inserted into a JScrollPane and the number of rows in the table is greater than the vieport size.
A random row within the table gets programmatically selected.
How to find out if the selected row is visible in a JTable visible area?
Your help will be greatly appreciated.
TimThat will make the row visible, but not answer whether it was visible
in the first place. Try something like:
public boolean isRowVisible( JTable table, int row ) {
Rectangle rect = table.getBounds();
int rowHeight = table.getRowHeight();
int viewHeight = table.getParent().getHeight();
int max = rect.y - viewHeight + 1;
int rowPos = - rowHeight * row;
return ( rect.y >= rowPos && rowPos > max );
}assuming all rows have the same height.
: jay -
JTable - set Selected row?
How do you set the current selected row and highlight it?
You use the public ListSelectionModel getSelectionModel()
method of your JTable. Once you have the ListSelectionModel you can use public void setSelectionInterval(int index0, int index1) to select one or more rows.
Depending on your selection mode you may or may not be able to select multiple rows. This is set by the ListSelectionModel's public int getSelectionMode() and public int setSelectionMode(int SelectionMode) methods.
Hope it helps.
Greg -
I have a JTable with many rows and X number of cols.
The user selects some rows.
I call getSelectedRows() to find out what rows have been selected.
I do some stuff and sort the rows. This loses the selection and the selected rows can be different numbers now.
How can I re-select the right rows....there is no setRowSelection(Object o).You'll need to figure out how to map from original to new row indices. Then use javax.swing.JTable.addRowSelectionInterval(int, int) to reselect. The Java tutorial provides a class called TableSorter that handles sorting and maintains an index map.
-
How to read 'clicked header' AND selected row from multicolumn listbox?
I have a multicolumn listbox filled with 6 columns and about 500 rows.
I want the user to be able to click on a column header, and sort the listbox alphabetically on that column. I've written the code for that, and that works. (using the 'itemnames' en 'get clicked col hdr' properties.)
However, I also want to include the option, that when a user highlights a row, and then clicks on the header, that after the listbox gets sorted it scrolls down to the selected row.
(So that the user doesn't have to search for it)
And that's where things go wrong, because the value of the listbox changes to zero when you click on a column header. No I idea why it does that, but it's rather
annoying. Can I change that behaviour somehow?
Or any ideas how to get around it?My thanks to you and Jared.
Seems I got a working solution now.
Did take a while to figure out why your solution worked. Basicly, you're reading the row from a few iterations before.
As soon as I understood that, I simplified it a little. Look at the attached file... I think it does the same. :-)
Jared asked for the sorting routine. As I don't seem to be able to attach files when replying to comments, I took the liberty to include it here also.
Basicly, I just use the 'sort 1D array' that comes with Labview 6. To be able to sort a 2D array, I convert every row to a cluster. That's something the 'sort 1D array' VI can handle nicely.
To sort on the correct column, I just cut all columns in front, and paste them behind again. A
fter sorting, I reverse the process.
Anthony.
Attachments:
copy2_of_multicolumn.vi 26 KB
sort_2d_string_array.vi 34 KB -
Refresh adf table and selection row
Hi,
I create web application. I have created entity Users from MySQL database and managed Bean. In this managed Bean (sessionScope) is method for connection to database and method for adding new row (data) in database. It works.
I have 2 problems.
The first.
I have form for adding User and commandButton Add.
How I can refresh (update) adf table after executing SQL command (in commandButton Add) ? Now I must reconnect session.
The second problem:
I want to show a panel with data from one row from adf table.
How I can selection this row in popup ?
My table:
<af:table var="user" rowBandingInterval="0" id="t2"
inlineStyle="margin:20px 30px; width:578pt; height:160pt;"
value="#{userController.users}"
rows="15"
emptyText="#{bindings.UsersprototypView11.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.UsersprototypView11.rangeSize}"
editingMode="clickToEdit" rowSelection="single"
selectedRowKeys="#{userController.selectedUser}"
selectionListener="#{userController.selectedUser}"> ---- Here I have problem.
<af:column sortProperty="#{user.user_id}"
sortable="false"
headerText="ID"
id="c11" width="33">
<af:commandLink id="ot34" text="#{user.user_id}">
<af:showPopupBehavior popupId="p4" triggerType="action"/>
</af:commandLink>
</af:column>
<af:column sortProperty="#{user.firstname}"
sortable="false"
headerText="Firstname"
id="c20" width="111">
<af:outputText value="#{user.firstname}" id="ot27"/>
</af:column>
<af:column sortProperty="#{user.lastname}"
sortable="false"
headerText="Lastname"
id="c12">
<af:outputText value="#{user.lastname}" id="ot31"/>
</af:column>
<af:column sortProperty="#{user.address}"
sortable="false"
headerText="Address"
id="c9" width="95">
<af:outputText value="#{user.address}" id="ot32"/>
</af:column>
<af:column sortProperty="#{user.city}"
sortable="false"
headerText="#City"
id="c10" width="76">
<af:outputText value="#{user.city}" id="ot33"/>
</af:column>
<af:column sortProperty="#{user.username}"
sortable="false"
headerText="Username"
id="c7" width="102">
<af:outputText value="#{user.username}" id="ot29"/>
</af:column>
<af:column sortProperty="#{user.email}"
sortable="false"
headerText="E-mail"
id="c21" width="106">
<af:outputText value="#{user.email}" id="ot28"/>
</af:column>
<af:column sortProperty="#{user.regdate}"
sortable="false"
headerText="Registration"
id="c8" width="108">
<af:outputText value="#{user.regdate}" id="ot30">
<af:convertDateTime pattern="#{user.regdate}"/>
</af:outputText>
</af:column>
</af:table>userController is name managed Bean.
users is list of users.
My panel window (popup):
<af:popup childCreation="deferred" autoCancel="disabled" id="p4">
<af:panelWindow id="pw9" title="Delete user">
<af:panelFormLayout id="pfl6">
<af:panelLabelAndMessage label="ID:"
id="plam16">
<af:outputText value="#{userController.selectedUser.user_id}" id="ot50"/>
</af:panelLabelAndMessage>
<af:panelLabelAndMessage label="Firstname:"
id="plam17">
<af:outputText value="#{userController.selectedUser.firstname}" id="ot51"/>
</af:panelLabelAndMessage>
<af:panelLabelAndMessage label="Lastname:"
id="plam18">
<af:outputText value="#{userController.selectedUser.lastname}" id="ot52"/>
</af:panelLabelAndMessage>
<af:panelLabelAndMessage label="Address:"
id="plam19">
<af:outputText value="#{userController.selectedUser.address}" id="ot53"/>
</af:panelLabelAndMessage>
<af:panelLabelAndMessage label="City:" id="plam20">
<af:outputText value="#{userController.selectedUser.city}" id="ot54"/>
</af:panelLabelAndMessage>
<af:panelLabelAndMessage label="Username:"
id="plam21">
<af:outputText value="#{userController.selectedUser.username}" id="ot55"/>
</af:panelLabelAndMessage>
<af:panelLabelAndMessage label="E-mail:" id="plam22">
<af:outputText value="#{userController.selectedUser.email}" id="ot56"/>
</af:panelLabelAndMessage>
<af:panelLabelAndMessage label="Registration:"
id="plam23">
<af:outputText value="#{userController.selectedUser.regdate}" id="ot57">
<af:convertDateTime pattern="#{userController.selectedUser.regdate}"/>
</af:outputText>
</af:panelLabelAndMessage>
</af:panelFormLayout>
<af:commandButton text="Delete" id="cb18"
inlineStyle="width:80pt; margin:10px 0px 0px 0px;"/>
</af:panelWindow>
</af:popup>When I cut out row: selectionListener="#{userController.selectedUser}
Popup (for deleting user) looks like this:
http://imageshack.us/photo/my-images/404/popupc.jpg/
I need to get the outputs from <af:outputText> in this popup.
Thanks for help.
Edited by: user9202624 on 26.2.2013 7:52thanks for answer.
I added partialTriggers in af:table
<af:table var="user" rowBandingInterval="0" id="t2"
inlineStyle="margin:20px 30px; width:578pt; height:160pt;"
value="#{userController.users}"
rows="15"
emptyText="#{bindings.UsersprototypView11.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.UsersprototypView11.rangeSize}"
editingMode="clickToEdit" rowSelection="single"
selectedRowKeys="#{userController.selectedUser}"
partialTriggers="::t1" >What next ? What should I do next ? Sry, I'm newbie in adf and jDev.
Edited by: user9202624 on 26.2.2013 8:55 -
Hi,
1. Can we adjust variable row height for each row,
2. Also as we adjust the column widht, can we adjust the row height by dragging,
3.Suppose i have JTextArea as a cell renderer , how can i display all the text in a row with out having to use a scroll bar,
AshishThat's a lot of questions..... but here are your answers:
1. Can we adjust variable row height for each row,Yes, use JTable's setRowHeight method to set the height of each row.
2. Also as we adjust the column widht, can we adjust the row height by dragging,You should be able to adjust the column width by clicking the mouse on the edge of the column header and drag. There is no automatic provision for changing the row height that way -- you'll have to add a mouse listener to the rowheader and write your own code to perform the resizing.
3.Suppose i have JTextArea as a cell renderer , how can i display all the text in a row with out having to use a scroll bar, You'll have to figure out how many rows (based on the sum of the individual row's height) the textarea occupies (taking into consideration the font that you used to render the textarea). I have my own way of doing things but if you search this forum, you'll find a lot of discussion on how to do it.
;o)
V.V. -
JTable and adjusting Row height
Hi,
How to make a row height adjustable, like user can click on the row and drap to increase the height of the row,
Also if i have JTextArea as cell rendere how do i dynamically adjust the row height to display all the text
AshishThat's a lot of questions..... but here are your answers:
1. Can we adjust variable row height for each row,Yes, use JTable's setRowHeight method to set the height of each row.
2. Also as we adjust the column widht, can we adjust the row height by dragging,You should be able to adjust the column width by clicking the mouse on the edge of the column header and drag. There is no automatic provision for changing the row height that way -- you'll have to add a mouse listener to the rowheader and write your own code to perform the resizing.
3.Suppose i have JTextArea as a cell renderer , how can i display all the text in a row with out having to use a scroll bar, You'll have to figure out how many rows (based on the sum of the individual row's height) the textarea occupies (taking into consideration the font that you used to render the textarea). I have my own way of doing things but if you search this forum, you'll find a lot of discussion on how to do it.
;o)
V.V. -
How to select rows in the inner JTable rendered in an outer JTable cell
I have wrriten the following code for creating cell specific renderer - JTable rendered in a cell of a JTable.
table=new JTable(data,columnNames)
public TableCellRenderer getCellRenderer(int row, int column)
if ((row == 0) && (column == 0))
return new ColorRenderer();
else if((row == 1) && (column == 0))
return new ColorRenderer1();
else
return super.getCellRenderer(row, column);
ColorRenderer and ColorRenderer1 are two inner classes, which implement TableCellRenderer to draw inner JTable on the outer JTable cell, having 2 rows and 1 column each.
Now what is happening the above code keeps executing continously, that is the classes are being initialised continously, inner JTables are rendered (drawn) continously, and this makes the application slow after some time. It throws java.lang.OutOfMemoryException.
WHY IS IT SO??? I can't understand where's the bug..
Any advice please???
Moreover i want selections in inner tables and not on outer table, how can this be possible.
I am working on this since a long time but have not yet found a way out...With your help i have overcome the problem of continous repeatition.
The major problem which I am facing is, in selecting rows in the inner rendered JTables.
I have added listener on outer JTable which select rows on the outer JTable, hence the complete inner JTable which being treated as a row, gets selected.
The thing is i need to select the rows of inner rendered JTables,not the outer JTable.
How to go about it??
I have even added listener to inner rendered JTables, but only first row of every table gets selected.
Please help....
Thanks in advance. -
JTable disable editing, row selecion
hii all,
i want to disable the cell editing in the JTable and select a complete row.
i tried with more than a way but faild.You have to write a separate CellEditor class with overriding isCellEditable() returning false.
public class MyTableCellEditor extends DefaultCellEditor
public MyTableCellEditor (JTextField textField)
super(textField);
public boolean isCellEditable(EventObject e)
return false;
public boolean shouldSelectCell()
return true;
and then get the TableColumn object, say tcm,of the JTable's Column.
And then tcm.setCellEditor(new MyCellEditor(new JTextField())) to an instance of the above CellEditor class.
And also call JTable methods as setRowSelectionEnabled(true) etc.. -
How to select row automatically in matrix (exp:automatic select row no 2)?
Hi
example i fill matrix row no 1 - 3 in serial number selection form or else (from database data)
and i want to automatic select row no 2
and i really have a big problem to do this
oQuant = edit text
oColumn = column
oForm = form
here some of my code
====================================
formID = pVal.FormUID
Set oForm = SBO_Application.Forms(formID)
Set oMatrix3 = oForm.Items.Item("5").Specific
Set oColumn3(3) = oMatrix3.Columns.Item("19")
Set oQuant(5) = oColumn3(3).Cells.Item(2).Specific
=====================================
i tried
oMatrix3.SelectRow 2, True, False
but it didn't work , it's said that not user defined item
oQuant(5).Active = True
it works but that not the select what i want
pls some one help me
i really need it right away
ThanksHi chetan
Thank You for your reply and yes i didn't write selection mode for my matrix
but when i tried both of these code it still didn't work (for information i'm using visual basic 6, so it has a different syntax about .net and VB6 - exp: for .net oMatrix.selectrow(2,true,false) , for VB6 oMatrix.selectrow 2,true,false )
oMatrix.SelectionMode = SAPbouiCOM.BoMatrixSelect.ms_Auto
oMatrix.SelectRow 2, True, False
oMatrix.SelectionMode = ms_Auto
oMatrix.SelectRow 2, True, False
is there any presiquities for selection mode ?? because I always have <b>warning</b> on oMatrix.selectionmode
"<b>Item - the item is not user defined item</b>"
Edit : it works when i created a form and select row no 2, but it didn't work with serial number selection form which the form is already exist in SBO (serial number selection is the form after klik add button in good issue form)
Thanks -
How to set the Selected row and Column in JTable
Hi,
i have a problem like the JTable having one Method getSelectedRow() and getSelectedColumn to know the Selected row and Column but if i want to explicitly set the Selected Row and Column,then there is no such type of Methods.If anybody has any solution then i will be thankful to him/her.
Praveen K SaxenaIs that what you're looking for? :myTable.getSelectionModel().setSelectionInterval(row, row);
myTable.getColumnModel().getSelectionModel().setSelectionInterval(column, column); -
Select row and column from header in jtable
hello i have a problem to select row and column from header in jtable..
can somebody give me an idea on how to write the program on it.Hi Vicky Liu,
Thank you for your reply. I'm sorry for not clear question.
Answer for your question:
1. First value of Open is item fiels in Dataset2 and this value only for first month (january). But for other month Open value get from Close in previous month.
* I have 2 Dataset , Dataset1 is all data for show in my report. Dataset2 is only first Open for first month
2. the picture for detail of my report
Detail for Red number:
1. tb_Open -> tb_Close in previous month but first month from item field in Dataset2
espression =FormatNumber(Code.GetOpening(Fields!month.Value,First(Fields!open.Value, "Dataset2")))
2. tb_TOTAL1 group on item_part = 1
expression =FormatNumber(Sum(CDbl(Fields!budget.Value)))
3. tb_TOTAL2 group on item_part = 3 or item_part = 4
expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) + ReportItems!tb_TOTAL1.Value )
4. tb_TOTAL3 group on item_part = 2
expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) - ReportItems!tb_TOTAL2 .Value)
5. tb_Close -> calculate from tb_TOTAL3 - tb_Open
expression =FormatNumber(Code.GetClosing(ReportItems!tb_TOTAL3.Value,ReportItems!tb_Open.Value))
I want to calculate the value of tb_Open and tb_Close. I try to use custom code for calculate them. tb_close is correct but tb_Open is not correct that show value = 0 .
My custom code:
Dim Shared prev_close As Double
Dim Shared now_close As Double
Dim Shared now_open As Double
Public Function GetClosing(TOTAL3 as Double,NowOpening as Double)
now_close = TOTAL3 + NowOpening
prev_close = now_close
Return now_close
End Function
Public Function GetOpening(Month as String,NowOpen as Double)
If Month = "1" Then
now_open = NowOpen
Else
now_open = prev_close
End If
Return now_open
End Function
Thanks alot for your help!
Regards
Panda A -
Overriding the SelectionForegroundColor of a selected row in a JTable
Hi
First, apologize for my poor English.
I looked for a similar topic in the forum, but coudn't find one.
What I want to achieve is this :
upon data contained in a column, I want the foreground color of the row to be gray. To do this, I write my own TableCellRenderer and it works perfectly except for the unique selected row of the table (single selection model) whose foreground color is the table's selectionForegroundColor.
I found a workaround...but the code is awful and leads to OutOfMemoryErrors.
Here is the code :
<
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
boolean isGrayColored = false;
// some process to set whether the foreground color should be gray
if (isGrayColored) {
//table.setSelectionForeground(Color.gray);
setForeground(Color.gray);
} else {
//table.setSelectionForeground(Color.black);
setForeground((isSelected) ? table.getSelectionForeground() : table.getForeground());
if (table != null && value == null && isSelected && hasFocus) {
return this;
} else {
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
>
If I uncomment the lines "table.setSelectionForeground(..", I got the expected result.
Thanks for your help
Regards,Try this:
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (isSelected && hasFocus) {
setForeground(Color.black);
} else {
setForeground(Color.gray);
setText((value==null)?"":""+value);
return this;
};o)
V.V.
PS: If it helps, don't forget the dukes!
Maybe you are looking for
-
Video from iPhone to iMovie on Mac and quality issues
Task: Wanting to take video from my iPhone 5 into iMovie HD Version 6.0.3 to do some editing, trimming, transitions, etc. I have done this on many occasions but have NEVER been able to share/export the finished product with any kind of quality resu
-
Two ipod nanos registered to same PC Both with own Apple ID Up until recently able to sync both ipods no problem Now, the 7th gen ipod nano, unable to sync and all music previously synced has dissappeard from ipod (thankfully still in itunes). Could
-
Javax.naming.NameNotFoundException while Message driven bean
I am adding a message driven bean in to my EJB application and trying to deploy it in the WebLogic 6.0 server. Now please let me know is there any other step i am missing. 1) This is what i have added in my ejb-jar.xml <enterprise-beans> <messag
-
Set_User: Where to call?
Experts, I have built a custom authentication schema. I have a table of usernames/pw in the database. I am using Page 101 to login. I am able to login to the application, and get a session id. Now I want to set the APP_USER. Is set_user(<username>) s
-
Identifying rings and edges with problems
Hi I have new polygon layers that produce a validation error for a polygon of gtype of 2007: 13350 [Element <1>] [Rings 1, 8][Edge <9> in ring <1>][Edge <33> in ring <8>] The error is: ORA-13350: two or more rings of a complex polygon touch Cause: Th