Arbitrary Individual Cell Selection
How do I select individual cells arbitrarily in a JTable ?
Regards,
Ram
LOL. Good one.
If that doesn't work, how about:myTable.changeSelection( row, column, false, false );
Similar Messages
-
I want to set up my spreadsheet to display two digits to the right of the decimal point, even if zeros, and not have to do it for each individual cell.
Select all the cells you want formatted that way (or the entire table if that's what you want)
Open the cell inspector
Set the format to "number" with 2 decimal places -
JTable - Select Individual Cell
After the user has made an error entering data into a cell of a table I am displaying an error dialog and then I would like to move the user back to the cell in error (if he has hit tab) and have the cell selected.
I have set :
tbl.setColumnSelectionAllowed(false);
tbl.setRowSelectionAllowed(false);
The tried the following and many variations there of and it did not work:
in method: public void setValueAt(Object value, int row, int col)
if (col == 2) {
try{
loc1.setFrameLocation( (String) value);
catch (AppException e) {
ErrorDisplay.displayAppException(tblPhysicalProfile, "Cell Error " + getTitleText(), e);
tbl.changeSelection(row, col, false, false);
}The row and col is correct but no cell selection occursI have different types of controls in the table and I only want this for specifc columnsYou can also assign editors to a specific class or column. Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#validtext]How to Use Tables for an example of assigning an editor to a class. To assign an editor to a column you would get the TableColumnModel and then get the TableColumn and assign the editor.
-
Hi All,
This thread actually follows on from another, which you can find here: Multiple tables feeding one table
I don't believe it is possible to reference specific cells in a table in the manner you have described. You can reference the cells in an individual selected row of a table by using the corresponding field/column name. However, I don't think you can reference individual cells anywhere in the table like you can with Excel spreadsheets for example.
Judging from the response quoted above, it will be possible to calculate values for Column4, if:
Column4 = Column2 + Column3.
Example 1
--Column1Column2---Column3-----Column4
Row 1 -
80--
85
95--
180
Row 2 -
100--
130
160--
290
Row 3 -
200--
210
220--
430
Row 4 -
200--240260--
zzz
But it will not be possible to calculate values for Column4 , if:
Column4 = a value from another row Column1 + value from row in Column2.
Example 2
--Column1Column2---Column3-----Column4
Row 1 -
80--
8595--
185
Row 2 -
100--
130160--
330
Row 3 -
200--
210220--
410
Row 4 -
200--240260--
xyz
It is highly desirable to be able to reference particular cells and their values in order to be able to manipulate them a little further (as this info is not available at BI Cube level; arrives from different BI queries).
Is anyone able to confirm please?
Regards,
Chet.Hi Chet,
Your understanding is accurate. As far as I am aware, it is not possible to achieve Example 2 because there is no way of specifiying the row reference for a table cell in a Visual Composer formula.
Since it is possible to perform cell calculations in BI, I would suggest that you try to define one BI query with all of the required information. In order to perform cell calculations in the query it must have a fixed layout, i.e. a column structure and a row structure.
Regards,
Mustafa. -
Setting cell editor for individual cell in JTable
Hi there,
I want to provide individual cell editor for my JTable. Basically, my JTable shows property names and values. I want to show different cell editors for different properties.
I followed the advice in this post:
http://forum.java.sun.com/thread.jsp?forum=57&thread=423318
but I have a question:
I looked at the code of DefaultCellEditor. It just has a single editor component (the one provided in the constructor), so all the methods use the same component and certain aspects are customized for the type of component. Again, there can be only one type of component at a time.The problem that I am facing is that I will have different components for different row/column of the same table. So how do I implement some of the methods (for example, getCellEditorValue()), when I have multiple editor components?
Also, how do I commit changes made by the user?
I am extremely confused.
Someone please help!
Thanks.Actually, that's what I am currently doing.
Here is my cell editor class:
public class ObjectPropertyEditor extends DefaultCellEditor
public ObjectPropertyEditor()
super(new JTextField());
Vector list = new Vector();
list.add("Yes");
list.add("No");
myCombo = new JComboBox(list);
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column)
String colName = (String)table.getValueAt(row,0);
if(colName.equalsIgnoreCase("Leaf-Node?")) //if it is the "Leaf" property, return the combo box as the editor
return myCombo;
else //for all other properties, use JTextField of the super class
return super.getTableCellEditorComponent(table,value,isSelected,row,column);
private JComboBox myCombo;
}The problem I have is that when I select a new item from the combo box, the new selection is not reflected in the tableModel. I don't know how I can achive that. I think I need the functionalities that DefaultCellEditor gives to its delegate when its constructor arguments is a combo box. But how can I get two different sets of functionalities (JTextField and JComboBox) ?
Please help!
Thanks. -
I am trying to change the width of a individual cell within a
table in Dreamweaver 8, however when I click and drag to change the
width, it also grabs the cell above it, changing both cells,
however I only want to have the width of one cell changed.
I know that to do it in Microsoft products, you select the
one cell, but I have great difficulty to select an individual cell
in Dreamweaver and do not think it works anyway.
Please could someone tell me how to do it please? Thank you
n.b. I am a designer, and would prefer to know via designing
techniquesThat's not how cells in a HTML table work.
You can try splitting your cell(s) and see how that works.
"The Kelvinater" <[email protected]> wrote
in message
news:etuioq$bun$[email protected]..
>I am trying to change the width of a individual cell
within a table in
> Dreamweaver 8, however when I click and drag to change
the width, it also
> grabs
> the cell above it, changing both cells, however I only
want to have the
> width
> of one cell changed.
>
> I know that to do it in Microsoft products, you select
the one cell, but I
> have great difficulty to select an individual cell in
Dreamweaver and do
> not
> think it works anyway.
>
> Please could someone tell me how to do it please? Thank
you
> -
Tables (Individual Cells) & CSS
I have a table in my webpage, which has 1 row and 5 columns
(just 5 cells within the table), when I select the whole table, and
apply the Style sheet, I get this code, I understand
why it is doing that, but the reason I provided this, was
because when I did the first method (applying it to the
whole table, nothing would show in the browser, just the
defaulted background etc.., however when I applied it to each
individual cell, it would show in the browser, any reasons to this?
Thanks:
<tr class="navigationBar">
<td width="20%" height="33"><div
align="center"><a
href="index.html">Home</a></div></td>
<td width="20%" height="33"><div
align="center"><a
href="News.html">News</a></div></td>
<td width="20%" height="33"><div
align="center"><a
href="cheats.html">Cheats</a></div></td>
<td width="20%" height="33"><div
align="center"><a href="new downloads.html">New
Downloads</a></div></td>
<td width="20%" height="33"><div
align="center"><a href="about us.html">About
Us</a></div></td>
</tr>
However, if I click each individual cell (Ctrl + Click), then
apply the style sheet, I get this code:
<tr>
<td width="20%" height="33"
class="navigationBar"><div align="center"><a
href="index.html">Home</a></div></td>
<td width="20%" height="33"
class="navigationBar"><div align="center"><a
href="News.html">News</a></div></td>
<td width="20%" height="33"
class="navigationBar"><div align="center"><a
href="cheats.html">Cheats</a></div></td>
<td width="20%" height="33"
class="navigationBar"><div align="center"><a
href="new downloads.html">New
Downloads</a></div></td>
<td width="20%" height="33"
class="navigationBar"><div align="center"><a
href="about us.html">About Us</a></div></td>
</tr>
p.s. sorry the code has been copied and pasted in, I could
not get the 'Attach Code" to work!In the first case the class is applied to <tr>, which
cannot show a
background image in IE. In the second case, the class is
applied to each
individual cell, which can show the background image. In
fact, in neither
case did you apply the class to the whole table (i.e., the
<table> tag).
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"The Kelvinater" <[email protected]> wrote
in message
news:[email protected]...
>I have a table in my webpage, which has 1 row and 5
columns (just 5 cells
> within the table), when I select the whole table, and
apply the Style
> sheet, I
> get this code, I understand
why it is doing that, but the reason I
> provided this, was because when I did the first method
(applying it to the
>
whole table, nothing would show in the browser, just the
defaulted
> background etc.., however when I applied it to each
individual cell, it
> would
> show in the browser, any reasons to this? Thanks:
>
>
<tr class="navigationBar">
> <td width="20%" height="33"><div
align="center"><a
>
href="index.html">Home</a></div></td>
> <td width="20%" height="33"><div
align="center"><a
>
href="News.html">News</a></div></td>
> <td width="20%" height="33"><div
align="center"><a
>
href="cheats.html">Cheats</a></div></td>
> <td width="20%" height="33"><div
align="center"><a href="new
> downloads.html">New
Downloads</a></div></td>
> <td width="20%" height="33"><div
align="center"><a href="about
> us.html">About Us</a></div></td>
> </tr>
>
> However, if I click each individual cell (Ctrl + Click),
then apply the
> style
> sheet, I get this code:
>
> <tr>
> <td width="20%" height="33"
class="navigationBar"><div align="center"><a
>
href="index.html">Home</a></div></td>
> <td width="20%" height="33"
class="navigationBar"><div align="center"><a
>
href="News.html">News</a></div></td>
> <td width="20%" height="33"
class="navigationBar"><div align="center"><a
>
href="cheats.html">Cheats</a></div></td>
> <td width="20%" height="33"
class="navigationBar"><div align="center"><a
> href="new downloads.html">New
Downloads</a></div></td>
> <td width="20%" height="33"
class="navigationBar"><div align="center"><a
> href="about us.html">About
Us</a></div></td>
> </tr>
>
> p.s. sorry the code has been copied and pasted in, I
could not get the
> 'Attach
> Code" to work!
> -
How to restrict the cell selection in JTable based on cell contents...
Hi all,
I have some problem related to table cell selection.
I have a table that represets the calendar of some month and year.
I have the restriction that at one time only one cell could be selected.
Now i want the cell seletion like this,
I want only those dates to be selected if that date is after 'today'.
that is I want to restrict the selection of previous dates.
how can i do this.
I have overridden the table methods like this, still no use.
table = new JTable(model) {
setOpaque(false);
setSurrendersFocusOnKeystroke(false);
setRowHeight(20);
JTableHeader header = getTableHeader();
header.setOpaque(false);
getTableHeader().setReorderingAllowed(false);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getTableHeader().setResizingAllowed(false);
setCellSelectionEnabled(true);
setFocusable(true);
setBackground(new Color(247, 251, 255));
setFont(newFont);
public boolean isCellEditable(int row, int col) {
return false;
public boolean isCellSelected(int row, int col) {
int r = getSelectedRow();
int c = getSelectedColumn();
String val = (String)getValueAt(r,c);
Calendar cal = Calendar.getInstance();
cal.set(currentYear+1900, month,Integer.parseInt(val));
Date d = cal.getTime();
Date currentDate = new Date();
if (d.before(currentDate)) {
return false;
} else {
return true;
Someone please help...
-SoniTry overriding the changeSelection(....) method of JTable.
public void changeSelection(int row, int column, boolean toggle, boolean extend)
if (d.after(currentDate)
super.changeSelection(row, column, toggle, extend);
} -
Hi everybody,
is it possible to make a single cell selectable in a table in Web Dynpro for ABAP?
In simple ABAP it is possible and you can catch the coordinate while raising an event (button).
In Web Dynpro when I am using "input fields" instead of "text view" for the cell editor I can go into a cell, but it isn't selected.
By the way the table should not be editable ...
Thanks for all answers ...Problem is solved.
Solution:
As described I have a context attribute "marked_cell" typed WDR_EXT_ATTRIBUTE_POINTER.
After selecting a cell my method behind the button could read the coordinates with the following code.
DATA lo_el_context TYPE REF TO if_wd_context_element.
DATA ls_context TYPE wd_this->element_context.
DATA lo_marked_cell LIKE ls_context-marked_cell.
DATA lv_marked_column TYPE string.
DATA lv_marked_row TYPE string.
* get element via lead selection
lo_el_context = wd_context->get_element( ).
* get single attribute
lo_el_context->get_attribute(
EXPORTING
name = `MARKED_CELL`
IMPORTING
value = lo_marked_cell ).
* lo_marked_cell contains direkt the column
lv_marked_column = lo_marked_cell-attribute_name.
* Additionaly we need the row number the user selected
lv_marked_row = lo_marked_cell-element->get_index( ). -
Making OnLoad work in individual cells in multiple rows
Dear Raj et al...
thanks for your help with getting the java applet (JMOL) working in individual cells/rows in report tables.
I now need some help with getting OnLoad to work in each row.
I am able to make it work in an HTML region (not in a report table) where I use <body #ONLOAD#> in the HTML region and OnLoad="document.jmol.loadinline(getElementById('P16_text').value)"; in the 'On Load' region in page template.
However if I use OnLoad="document.jmol#AUTOKEY#.loadinline(getElementById('f01_#ROWNUM#').value)";
and put body tags in the Report Attributes\Column Formatting\html expression region where I have embeded the applet tags it doesn't work.
I don't think the #AUTOKEY# and #ROWNUM# are the problem as I also tried explicitly naming the objects:
OnLoad="document.jmol1.loadinline(getElementById('f01_1').value)";
and it still didn't work.
Again any suggestions will be greatly appreciated!
-DaveActually I take that back...
"I don't think the #AUTOKEY# and #ROWNUM# are the problem as I also tried explicitly naming the objects:
OnLoad="document.jmol1.loadinline(getElementById('f01_1').value)"; and it still didn't work."
The reason this didn't work is that I had two javascript calls in the on load section and I obviously didn't format them properly (the first worked not the second).
In any case, this worked once it was made the only javascript call in the on load section.
When I tried to use #AUTOKEY# or #ROWNUM# these were then flagged with an "Invalid Character" error.
Do you have any suggestions as how to have variable names put in the "OnLoad" statement and will it work for the n rows that are queried?
Thanks a lot!
-Dave -
Problem in cell selection in JTable Java Swing
hii
I am using JTable that shows data from database. I have developed one functionality. I change one cell value and then select multiple cell. If I press F12 function key then it copies first selected value and past it to another selected cells. it is working properly but when I press F12 it sets the last selected cell in editable mode. I want that all cell which has been pasted should be selected (with default blue colour not in editing mode). I am using ListSelectionListener for JTable Cell Selection and KeyListener for F12 functionality.
Please give some solution
I can not override editCellAt Method because i have already extended JFrame. and i tried to do this with Jtable.getSelectedColumn and getSelectedRow it is displaying the same value, by this how can I get the particular area of selection means Row nd Column Selected.
How would I know the current selection when user selects more than one cell???
Thanks
Edited by: 850979 on 11-Apr-2011 02:13
Edited by: 850979 on 11-Apr-2011 03:59camickr wrote:
Presumably, JTable installs an action for the F12 key that results in starting editing the last selected cell.
There are no bindings for F12. See the [url http://www.camick.com/java/blog.html?name=key-bindings]Key Bindings listing. (...)
Right.
Of course it doesn't make sense that a F? key should invoke the editorI thought he meant F2 ("edit" on Windows), so that sounded natural.
All KeyEvents are passed to the editor for the cell and the editor is psuedo invoked. That is, the caret is not placed on the text field used as the editor, but the character typed is added to the editor. You can then either use tab/enter to save the text or use the escape key to cancel the editing.Thanks for the explanation. I had never noticed (I kept on double-clicking my JTable cells when I wanted to edit them! :o)
Of course it doesn't make sense that a F? key should invoke the editor, but this is a by product of all KeyEvents being forwarded so you don't have to have special Key Bindings for every character.You're right - as always.
They (Sun) could have filtered out some of the keys such as those, though, because as noted by the OP the current behavior is unintuitive.
To better control when the cell is editable based on the KeyEvent you can override the table with code like <snipped>
As you suggested using a Key Binding will prevent this behaviour as well (but only for that key).Right again, but in this specific case that is acceptable (the developer wants to attach a specific behavior to a specific key only).
OP here is an SSCCE of that second approach:
public class TestKeyBindingsOnJTable {
public static void main(String... args) {
final DefaultTableModel dtm = new DefaultTableModel(new String[] {"A", "B"}, 0);
dtm.addRow(new String[]{"A1", "B1"});
dtm.addRow(new String[]{"A2", "B2"});
dtm.addRow(new String[]{"A3", "B3"});
JTable table = new JTable(dtm);
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), "clear");
table.getActionMap().put("clear", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
dtm.removeRow(0);
JOptionPane.showMessageDialog(null, table);
}Edited by: jduprez on Apr 8, 2011 9:36 PM -
Jtable in cell how to single mouse click make the cell selected.
it seems need double click make cell selected.
thanks!!!Hi,
these link will help you.
It has code for both examples, with 1 click and with 2 clicks:
http://forum.java.sun.com/thread.jsp?forum=57&thread=362073&tstart=0&trange=15
sergio. -
How do you change the colors of individual cells within a 2D array?
How do you change the colors of individual cells within a 2D array of numeric indicators?
I want the VI to check a data value and if it is failing, white out a square at a specific index coordinate. I have it working with color boxes, but I'm not sure how to use the property node function, to change the color of individual cells, by coordinates.
I have attached the VI using color boxes. If you run the VI, the box corresponding to the Step control should turn white.
I want to do the same thing, using numeric indicator boxes inside the array.
Thanks for any suggestions...
Attachments:
Fill DME matrix.vi 95 KBGet rid of all these sequences! That's just bad form.
Your code has a few logical problems. Why do you create a boolean array if you later only look at the last element (Yes, the FOR loop does nothing useful, except in the last iteration because your outputs are not indexing. All other iterations are useless, you only get the result of the last array element. My guess is that you want to color the index white if at least one of the numbers is out if range. Right?
It is an absolute nightmare to manage all your numeric labels. Just read them from a 2D array. Now you can simply find the index of the matched elements and don't have to spend hours editing case structure conditions.
Attached is a simple example how you would do what I meant (LV7.1). Modify as needed.
Message Edited by altenbach on 04-04-2006 02:04 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
Fill_2DME_matrixMOD.vi 70 KB -
How to do Multi Cell Selection in JTable
Dear Friends,
Any body know Multi cell selection in jtable......
ThanksTry overriding the changeSelection(....) method of JTable.
public void changeSelection(int row, int column, boolean toggle, boolean extend)
if (d.after(currentDate)
super.changeSelection(row, column, toggle, extend);
} -
Adding ToolTip for individual cell in the table
Hi everybody,
Its urgent. I want to add ToolTip for individual cells. What I have implemented, it show same ToolTip for each cell. I want different ToolTip for individual cell.
My cells are not editable, as i need this.
Pleae help me.
Thanks in Advance.
DawoodzaiHi,
See this demo pasted below-
import java.awt.*;
import javax.swing.*;
public class SimpleTableDemo extends JFrame {
public SimpleTableDemo() {
super("SimpleTableDemo");
Object[][] data = {
{"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath", "Chasing toddlers", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)},
{"Angela", "Lih", "Teaching high school", new Integer(4), new Boolean(false)}
String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
final JTable table = new MyTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
JScrollPane scrollPane = new JScrollPane(table);
getContentPane().add(scrollPane, BorderLayout.CENTER);
public static void main(String[] args) {
SimpleTableDemo frame = new SimpleTableDemo();
frame.pack();
frame.setVisible(true);
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyTable extends JTable {
public MyTable(Object[][] rowData, Object[] columnNames) {
super(rowData,columnNames);
public String getToolTipText(MouseEvent e) {
int r = rowAtPoint(e.getPoint());
int c = columnAtPoint(e.getPoint());
return getValueAt(r,c).toString();
}
Maybe you are looking for
-
Hello All, I have a requirement to design a workflow for payment for a purchase order like while the finance people release a amount for purchase based on the amount it should take the approval from the concerned person and should allow the purchase
-
I would like to improve the quality of my iTunes library, most of which were ripped at the old 'higher quality' setting and not lossless. I would consider subscribing to the iTunes Match programme if I would later be able to download my music back on
-
Unable to install the scanner on the HP LaserJet Pro 200 color MFP M276nw in windows 7 64 bit
HI am unable to install the scanner on the HP LaserJet Pro 200 color MFP M276nw Drivers in windows 7 64 bit , after runing the setup ,the printer will finshing the installation process and and it will show that the HP Scan and HP fax failed.
-
J2E instance not working / jcontrol.exe stopped after DB password changes
Hi, i have changed my MAXDB user(SAPJ2EDB) password in config tool in secure store node (parameter: jdbc/pool/J2E/Password). After the password changes, when i re-started the server, my J2E instance is not started running. The jcontrol.exe file is st
-
OS X Server 10.4.7 as router to internet
Hello, I am trying to set up a gateway to the internet through my g5 server. I have tried the gateway setup assistant but it doesn't really do what i need it to do. I already have a DHCP server and DNS running on the AD that the servers are integrate