URGENT!!! How to set focus to a required cell in JTable with ENTER
Hello everybody,
I want to change the focus to the cell(identified by row, column) while pressing ENTER. Pleas help me on this issue.
Hello Venkatesh. Yes that code does work. First I tried it on a table cell that was already rendered and it did work. The next time I tried it on a table row that was being added and it did not work there. So I added an on after rendering function for the table and added that code there. That did not work until I added a delay (timeout) to do a context switch before calling the focus and that worked.
Once last thing though sometimes when I call focus on an input field (actually in a table row cell) if the field has text in it already the flashing cursor is at the beginning of the text and other times it is at the end of the text (which is the desired way). It depends on where I click in the row. Is there anyway to make sure the flashing cursor is at the end of the text when the focus is applied to a field that contains text?
Similar Messages
-
Setting Focus to a particular cell in JTable
Hi, can i know how to set the focus to a particular cell in JTable.
Say I have a table with 2 rows and 10 columns. The focus now is at position (1, 9) which is the last cell in the table. But I want to set the focus to (1, 3). How can i achieve this ? Pls help. ThanksOK. It's partially working. The right methods to use are setRowSelectionInterval and setColumnSelectionInterval. Jeanette was right. Mine didn't work because of a thread issue. I put the those two methods in a block such as:
SwingUtilities.invokeLater(new Runnable(){
public void run()
table.setRowSelectionInterval(tblLineItem.getRowCount()-1,
table.getRowCount()-1);
table.setColumnSelectionInterval(0,0);
Then it worked.
But after I finished editing the first cell of the newly created row and press ENTER, the selection went back to the cell that's next to the originally editing cell on the first(old) row, instead of staying at the current row and going to the second cell.
Can anybody shed a light on what I'm missing? -
How to set focus to a invalid cell in setValue method of custom TableModel
I am using a Jtable with an AbstractTableModel. In the setValueAt()
method I do validation of the data entered. If the data is invalid, I
show a dialog box with the error message. The focus goes to the next
cell or wherever it is tabbed out/clicked on. How can I get the
focusto stay in the invalid data cell ?Thank you all for the help! Definitely extending the DefaultCellEditor is one way.
I am wondering anything can be done from within the setValueAt method, Here is a code snippet i am using for doing validation inside my table model.
public void setValueAt(Object value, int row, int col)
EmployeeDetail empDtls = (EmployeeDetail(empList.elementAt(row));
switch(col){
case SSN_COL :
if(!GenericValidator.isLong((String)value)){
TaxUtil.HAS_ERROR = true;
JOptionPane.showMessageDialog(null, "SSN should be numeric only", "Error", JOptionPane.ERROR_MESSAGE);
return;
if(!GenericValidator.maxLength((String)value,SSN_LEN)){
TaxUtil.HAS_ERROR = true;
JOptionPane.showMessageDialog(null, "SSN should be of maximum 9 digits only", "Error", JOptionPane.ERROR_MESSAGE);
return;
empDtls.setSSN((String)value);
break;
case FNAME_COL :
if(!GenericValidator.maxLength((String)value,FIRST_NAME_LEN)){
TaxUtil.HAS_ERROR = true;
JOptionPane.showMessageDialog(null, "First Name should be of maximum 10 characters only", "Error", JOptionPane.ERROR_MESSAGE);
return;
empDtls.setFirstName((String)value);
break;
} -
How to set the width of a cell in JTable?
I have created a JTable and I want to set the width of cells.How can I do that?
This is now the third person to tell you that Swing questions should be posted in the Swing forum.
You have several postings out there where you have been given an answer but you haven't bothered to respond to the posting. Indicating whether the suggestion was helpfull or not. I guess you really don't want help from people in the future. -
How to set focus to required component in the application
Hi all,
Based on user events, I want to set focus dynamically to required component/panel in the application.
Is this possible? is yes, pls give me api for that![http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JComponent.html#requestFocusInWindow()]
A panel is not focusable by default.
If you want a panel to get the focus you have to use panel.setFocusable(true) first. -
How to set focus order of multiple Component in a Frame
I have created a Frame with contain some Label, Textfield, Choice and Buttons
How do set focus order on these Componentswrite an implementation of
import java.awt.*;
public class PanelFocusTraversalPolicy extends FocusTraversalPolicy
public Component getComponentAfter(Container container, Component component)
if(component.equals(cmp1))
return cmp2;
if(component.equals(cmp2))
return cmp3;
return cmp1;
public Component getComponentBefore(Container container, Component component)
//implentation of method
public Component getDefaultComponent(Container container)
return cmp1;
public Component getLastComponent(Container container)
return cmp3;
public Component getFirstComponent(Container container)
return cmp1;
public PanelFocusTraversalPolicy()
}and set the focus traversal of frame.
setFocusTraversalPolicy(new PanelFocusTraversalPolicy()) -
How to set focus on UI Element
Hi All,
I am using the below code to set the focus on the first row of the table given in the link [How to set focus at UI element ? ] on enter of an event.
data: lr_elem type ref to if_wd_view_element.
lr_elem = view->get_element( <ID of the Link to Action field>).
if lr_elem is bound.
view->request_focus_on_view_elem( lr_elem ).
endif.
I am getting "Cannot use NULL reference as object error at view".
Can you please tell me how to get the reference of the "view".
Thanks
Praveen>
praveenkumar_81 wrote:
> Hi All,
>
> I am using the below code to set the focus on the first row of the table given in the link [How to set focus at UI element ? ] on enter of an event.
>
>
data: lr_elem type ref to if_wd_view_element.
> lr_elem = view->get_element( <ID of the Link to Action field>).
>
> if lr_elem is bound.
> view->request_focus_on_view_elem( lr_elem ).
> endif.
>
> I am getting "Cannot use NULL reference as object error at view".
>
> Can you please tell me how to get the reference of the "view".
>
> Thanks
> Praveen
Hallo Praveen,
have you controlled that id of the Linktoaction ? there you made error.
See it in the ViewElement designer .
should be something like this
lr_elem = view->get_element( 'LTA_name ' ). -
How to set focus on next row inputfield in table
Hello all,
How to set focus on next row input field in table
Please help.
Thanks in advance.
CSPHi,
use the following code
wdThis.wdGetAPI().requestFocus(nodeElement, attribute)
Ex:
Provide the attribute and replace the nodeElement with that of yours
IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute("Your attribute");
wdThis.wdGetAPI().requestFocus(wdContext.currentContextElement(), attributeInfo);
Regards
Ayyapparaj -
How to set focus on an element inside a datatable on load
How to set focus on an element inside a datatable on load
Check out https://blogs.oracle.com/groundside/entry/ever_wondered_how_uncommitteddatawarning_works and
Decompiling ADF Binaries: Checking for dirty data
Timo -
How to set focus on the last row of JTextPane
how to set focus on the last row of JTextPane?
import javax.swing.*;
import javax.swing.text.html.*;
import java.awt.*;
import java.awt.event.*;
public class MyGUITest extends JPanel implements ActionListener
{ public static void main(String[] args)
{ SwingUtilities.invokeLater(new Runnable()
{ public void run()
{ JFrame f = new JFrame("My GUI");
MyGUITest GUI = new MyGUITest();
GUI.setOpaque(true);
f.setContentPane(GUI);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
JTextPane txtP;
JButton add;
HTMLEditorKit hek;
HTMLDocument hd;
String txt;
MyGUITest()
{ this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(400,200));
txtP = new JTextPane();
txtP.setEditable(false);
txtP.setContentType("text/html");
txtP.setText("");
hek = new HTMLEditorKit();
txtP.setEditorKit(hek);
hd = new HTMLDocument();
txtP.setDocument(hd);
JScrollPane sTxtA = new JScrollPane(txtP);
add = new JButton("add");
add.addActionListener(this);
sTxtA.setBorder(BorderFactory.createTitledBorder(""));
this.add(sTxtA, BorderLayout.CENTER);
add(add, BorderLayout.SOUTH);
new Thread(new Runnable()
{ public void run()
{ while(true)
{ try
{ Thread.sleep(100);
}catch(InterruptedException ex)
{ ex.printStackTrace();
appendText("This is <b>HTML</b> text");
//add.doClick();
}).start();
public void actionPerformed(ActionEvent e)
{ txt = "<b>asd</b>";
try
{ hek.insertHTML(hd, hd.getLength(), txt, 0, 0, null);
}catch(Exception ex){ ex.printStackTrace(); }
public void appendText(String txt)
{ try
{ hek.insertHTML(hd, hd.getLength(), txt, 0, 0, null);
}catch(Exception ex){ ex.printStackTrace(); }
}thanks~anIdiot wrote:
im not sure what is the caret location...So don't youthink you should have looked for it in the API?
anyway, i want the scroll bar to scrolled down automatically when the output is displayed.
normally, the scroll bar is scrolled down automatically when a new text is inserted, but it doesnt work on this timeGo through camockr's http://tips4java.wordpress.com/2008/10/22/text-area-scrolling/
db -
How to set focus programmatically in a table ?
Sir,
How to set focus programmatically in a table using javascript?
Is it document.getElementById('form1:table1:i:column1').focus(); ?
Thanks
StephenRepost
-
I have an airport express and want to know how to set up two different wireless networks. One with 5GHZ and one with 2.4GHZ so different devices can connect to either. I have an iphone 4 that will not connect to 5ghz.
thank you!Your AirPort Express is already providing two separate 2.4 GHz and 5 GHz bands, but each band is using the same wireless network name.
This is the default setup for the AirPort Express, which is recommended for most users. The theory here is that devices will automatically connect to the best quality signal based on their capabilities and distance in relation to the AirPort Express.
It is possible to assign a different name to the 5 GHz band, and then "point" devices at that network to connect. Some users swear by this option.....(I am not one of them).... but you might want to give it a try to see how it works for you.
Open Macintosh HD > Applications > Utilities > AirPort Utility
Click on the AirPort Express
Click Edit in the smaller window that appears
Click the Wireless tab at the top of the next window
Click Wireless Options near the bottom of the next window
Enter a check mark next to 5 GHz Name.....which will automatically add "5 GHz" to the network name....so you can identify it
Click Save, then click Update and wait a full minute for the Express to restart
Now you will need to "point" your 5 GHz capable devices at the 5 GHz network name. 2.4 GHz devices will connect to your "other" network name. -
How to set exponential format for a cell?
Hello! Can someone advise how to set exponential format for a cell in Numbers?
Hi Alejandro,
If you mean 1000 as 1E+03
Format Panel > Cell > Data Format > Scientific
Regards,
Ian. -
How to set focus and mark red on certain select option field
hi experts
I embedded a select_option view in my application and tried to use IF_WD_SELECT_OPTIONS->request_focus to set focus on a certain select option field if the logical check failed, and also hope the low field of the select option can be marked red....but things does not happen that way....
could anyone kindly tell me how to implement that requirement?
tkx and regards
sunWhat is the problem you are facing in this ?
Requesting focus is easy.
just call the method request focus and pass the id of the parameter whose lower value field you want to focus.
as shown below.
code you might have written in wddoinit
DATA: LT_RANGE_TABLE TYPE REF TO DATA,
RT_RANGE_TABLE TYPE REF TO DATA,
READ_ONLY TYPE ABAP_BOOL,
TYPENAME TYPE STRING.
DATA: LR_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER,
L_REF_CMP_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE.
* * create the used component
L_REF_CMP_USAGE = WD_THIS->WD_CPUSE_SELECT_OPTIONS( ).
IF L_REF_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL.
L_REF_CMP_USAGE->CREATE_COMPONENT( ).
ENDIF.
WD_THIS->M_WD_SELECT_OPTIONS = WD_THIS->WD_CPIFC_SELECT_OPTIONS( ).
WD_THIS->M_HANDLER = WD_THIS->M_WD_SELECT_OPTIONS->INIT_SELECTION_SCREEN( ).
LT_RANGE_TABLE = WD_THIS->M_HANDLER->CREATE_RANGE_TABLE( I_TYPENAME = 'ZDEALERID' ).
* * add a new field to the selection
WD_THIS->M_HANDLER->ADD_SELECTION_FIELD( I_ID = 'ID'
IT_RESULT = LT_RANGE_TABLE I_READ_ONLY = READ_ONLY ).
code for focusing a field.
wd_this->m_handler->request_focus( i_id = 'ID' ).
you must have declared attributes m_handler and m_wd_select_options type reffering to IF_WD_SELECT_OPTIONS and
IWCI_WDR_SELECT_OPTIONS respectively.
and regarding that red color i am not sure it is possible without using message manager.
thanks
sarbjeet -
How to set focus on invisible input field?
Hi Guys,
I need an invisible input field and have to set an input focus on it. My problem is that if I set input fields property visible=blank, I get my invisible field <b>BUT</b> the function call doesnt work (setInput.requestFocus()).
I suppose that I cant set a focus if an input field is invisible.
Does somebody know how can I solve my problem? Is there a possibility to do this input field invisible with java script? If yes, how does it work in Web Dynpro?
Thanks
MaritaHi
Setting a focus on invisible input field will not work even if you follow the method what sowjanya has suggested. The method wdThis.wdGetAPI().requestFocus() will not work for read-only and disabled fields.
By the way why do you want to set the focus on a invisible input field. If you can tell us the requirement maybe we could think of an alternate solution. But i guess for the current scenario setting focus on invisible input field does not work.
regards
ravi
Maybe you are looking for
-
Hi All, We are working on a series of Performance testing Scenarios for Unified Key Mapping (UKM). We have function modules present in the XI machine which do the UKM translations. we plan to invoke this modules by using RFC call. What I would like t
-
Calling of stored procedure in package
Hi, I have one stored procedure A. And one package of name P1. I have execute previlage of package but not having any previlge of stored procedure. and In package P1 stored procedure A is called. then this packege is work or it will genrate an Error?
-
I have 2 iPads but just one ID. I use the iPad 2 and my daughter uses the mini. Both have different contents, as her mini contains a lot of videos that she's taken. Niw, I just bought an iPad Air and want to essentially transfer my iPad 2 contents th
-
Automatic confirmation of activities from MM and PP
We have had a request in our post go live for automatically confirming activities such Purchase Order confirmation and Release of a Production Order to automatically update the status in SAP PS to the direct activity it is linked through the WBS. Hav
-
We try to use FME to capture and stream video from different kinds of sources. These streames are to be treated in different ways. Sometimes they will be streamed via FMS live or/and on demand, sometimes they will be made available for download. To s