Need focus in JTextArea
Hai Friends,
I am on the way of developing a QUERY ANALYSER. Mean while i got a problem. in my product I am using two JTabbedPanes(1 & 2).
In TabbedPane1 i have a text area (to write the query) and the tabbedpane2 on which two panes( one for dispaying the result on a JTable and other for displaying messages.).
On running my application I like to see the cursor blinking on the JTextArea.
How it can be possible?
Do you like to need some more explanation?
some one help me.....
Tino Simon.
.
Try this :
mytextarea.requestFocus();
to give focus to your textarea called "mytextarea"
Similar Messages
-
Buttons in ALV Grid cell need focus to be clicked :-(
Hi,
I have an ALV Grid with single cells displayed as buttons (dependend on the data in the corresponding row). Unfortunatelly the button-cells need focus to be clicked. So you need two clicks: one to get the focus to the desired cell and one to really click the button.
Any ideas how to make this work with one single click ? (Setting a hotspot does not work, cause hotspots have the same problem.)
Regards,
TobiHello Tobias
The proposal by Naimesh is valid for CL_GUI_ALV_GRID, too. You may have a look at sample report ZUS_SDN_ALVGRID_EVENTS_HOTSPOT. Put the focus on any non-button cell and next click on any customer button.
*& Report ZUS_SDN_ALVGRID_EVENTS_HOTSPOT
*& Thread: Buttons in ALV Grid cell need focus to be clicked :-(
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1009251"></a>
REPORT zus_sdn_alvgrid_events_hotspot.
DATA:
gd_okcode TYPE ui_func,
gt_fcat TYPE lvc_t_fcat,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid1 TYPE REF TO cl_gui_alv_grid.
DATA:
go_table TYPE REF TO cl_salv_table,
go_grid_adapter TYPE REF TO cl_salv_grid_adapter.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1.
PARAMETERS:
p_bukrs TYPE bukrs DEFAULT '2000' OBLIGATORY.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender, " grid instance that raised the event
handle_button_click FOR EVENT button_click OF cl_gui_alv_grid
IMPORTING
es_col_id
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_hotspot_click.
* define local data
DATA:
ls_knb1 TYPE knb1,
ls_col_id TYPE lvc_s_col.
READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row_id-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
CASE e_column_id-fieldname.
WHEN 'KUNNR'.
SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
WHEN 'ERNAM'.
* SET PARAMETER ID 'USR' FIELD ls_knb1-ernam.
* NOTE: no parameter id available, yet simply show the priciple
CALL TRANSACTION 'SU01' AND SKIP FIRST SCREEN.
WHEN OTHERS.
* do nothing
ENDCASE.
* Set active cell to field BUKRS otherwise the focus is still on
* field KUNNR which will always raise event HOTSPOT_CLICK
ls_col_id-fieldname = 'BUKRS'.
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
is_row_id = e_row_id
is_column_id = ls_col_id.
ENDMETHOD. "handle_hotspot_click
METHOD handle_button_click.
* define local data
DATA:
ls_knb1 TYPE knb1.
READ TABLE gt_knb1 INTO ls_knb1 INDEX es_row_no-row_id.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
ENDMETHOD. "handle_button_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_knb1
WHERE bukrs = p_bukrs.
** TRY.
** CALL METHOD cl_salv_table=>factory
*** EXPORTING
*** LIST_DISPLAY = IF_SALV_C_BOOL_SAP=>FALSE
*** R_CONTAINER =
*** CONTAINER_NAME =
** IMPORTING
** r_salv_table = go_table
** CHANGING
** t_table = gt_knb1.
** CATCH cx_salv_msg .
** ENDTRY.
** go_table->display( ).
** go_table->get_metadata( ).
** EXIT.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grid
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_docking
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Set event handler
SET HANDLER:
lcl_eventhandler=>handle_hotspot_click FOR go_grid1,
lcl_eventhandler=>handle_button_click FOR go_grid1.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog_knb1.
* Display data
CALL METHOD go_grid1->set_table_for_first_display
CHANGING
it_outtab = gt_knb1
it_fieldcatalog = gt_fcat
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form BUILD_FIELDCATALOG_KNB1
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog_knb1 .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'KNB1'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT gt_fcat INTO ls_fcat
WHERE ( fieldname = 'KUNNR' OR
fieldname = 'ERNAM' OR
fieldname = 'BUKRS' ).
IF ( ls_fcat-fieldname = 'BUKRS' ).
ls_fcat-style = cl_gui_alv_grid=>mc_style_button.
" column appears as button
ELSEIF ( ls_fcat-fieldname = 'KUNNR' ).
ls_fcat-style = cl_gui_alv_grid=>mc_style_button.
ls_fcat-hotspot = abap_true.
ELSE.
ls_fcat-hotspot = abap_true.
ENDIF.
MODIFY gt_fcat FROM ls_fcat.
ENDLOOP.
ENDFORM. " BUILD_FIELDCATALOG_KNB1
Regards
Uwe -
Problematic focus traversal (JTextArea)
I have a data entry dialog with several JTextFields and one JTextArea.
Focus traversal (with the tab key) works nicely between instances of JTextField, but it is not possible to tab out of the JTextArea to the next JTextField (as a tab is inserted in the text area instead). I've have looked up swing focus traversal in books, but no cigar when it comes to dealing with JTextAreas
Does anyone know how to fix this? I don't need to enter tabs into the text area.
thanks,
AndyThere is a Swing forum for Swing related questions.
Have you tried searching the forum?. Using keywords "+jtextarea +tab" would be a good place to start. You'll be amazed how many times this question has been asked/answered before.
This example shows two different approaches for tabbing out of a JTextArea
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
public class TextAreaTab extends JFrame
public TextAreaTab()
// Reset the FocusManager
JTextArea textArea1 = new JTextArea(5, 30);
textArea1.setText("1\n2\n3\n4\n5\n6\n7\n8\n9");
JScrollPane scrollPane1 = new JScrollPane( textArea1 );
getContentPane().add(scrollPane1, BorderLayout.NORTH);
textArea1.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
textArea1.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
scrollPane1.getVerticalScrollBar().setFocusable(false);
scrollPane1.getHorizontalScrollBar().setFocusable(false);
// Replace the Tab Actions
JTextArea textArea2 = new JTextArea(5, 30);
textArea2.setText("1\n2\n3\n4\n5\n6\n7\n8\n9");
getContentPane().add(new JScrollPane(textArea2), BorderLayout.SOUTH);
InputMap im = textArea2.getInputMap();
KeyStroke tab = KeyStroke.getKeyStroke("TAB");
textArea2.getActionMap().put(im.get(tab), new TabAction(true));
KeyStroke shiftTab = KeyStroke.getKeyStroke("shift TAB");
im.put(shiftTab, shiftTab);
textArea2.getActionMap().put(im.get(shiftTab), new TabAction(false));
class TabAction extends AbstractAction
private boolean forward;
public TabAction(boolean forward)
this.forward = forward;
public void actionPerformed(ActionEvent e)
if (forward)
tabForward();
else
tabBackward();
private void tabForward()
final KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
manager.focusNextComponent();
SwingUtilities.invokeLater(new Runnable()
public void run()
if (manager.getFocusOwner() instanceof JScrollBar)
manager.focusNextComponent();
private void tabBackward()
final KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
manager.focusPreviousComponent();
SwingUtilities.invokeLater(new Runnable()
public void run()
if (manager.getFocusOwner() instanceof JScrollBar)
manager.focusPreviousComponent();
public static void main(String[] args)
TextAreaTab frame = new TextAreaTab();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true); -
Need help with JTextArea and Scrolling
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.*;
public class MORT_RETRY extends JFrame implements ActionListener
private JPanel keypad;
private JPanel buttons;
private JTextField lcdLoanAmt;
private JTextField lcdInterestRate;
private JTextField lcdTerm;
private JTextField lcdMonthlyPmt;
private JTextArea displayArea;
private JButton CalculateBtn;
private JButton ClrBtn;
private JButton CloseBtn;
private JButton Amortize;
private JScrollPane scroll;
private DecimalFormat calcPattern = new DecimalFormat("$###,###.00");
private String[] rateTerm = {"", "7years @ 5.35%", "15years @ 5.5%", "30years @ 5.75%"};
private JComboBox rateTermList;
double interest[] = {5.35, 5.5, 5.75};
int term[] = {7, 15, 30};
double balance, interestAmt, monthlyInterest, monthlyPayment, monPmtInt, monPmtPrin;
int termInMonths, month, termLoop, monthLoop;
public MORT_RETRY()
Container pane = getContentPane();
lcdLoanAmt = new JTextField();
lcdMonthlyPmt = new JTextField();
displayArea = new JTextArea();//DEFINE COMBOBOX AND SCROLL
rateTermList = new JComboBox(rateTerm);
scroll = new JScrollPane(displayArea);
scroll.setSize(600,170);
scroll.setLocation(150,270);//DEFINE BUTTONS
CalculateBtn = new JButton("Calculate");
ClrBtn = new JButton("Clear Fields");
CloseBtn = new JButton("Close");
Amortize = new JButton("Amortize");//DEFINE PANEL(S)
keypad = new JPanel();
buttons = new JPanel();//DEFINE KEYPAD PANEL LAYOUT
keypad.setLayout(new GridLayout( 4, 2, 5, 5));//SET CONTROLS ON KEYPAD PANEL
keypad.add(new JLabel("Loan Amount$ : "));
keypad.add(lcdLoanAmt);
keypad.add(new JLabel("Term of loan and Interest Rate: "));
keypad.add(rateTermList);
keypad.add(new JLabel("Monthly Payment : "));
keypad.add(lcdMonthlyPmt);
lcdMonthlyPmt.setEditable(false);
keypad.add(new JLabel("Amortize Table:"));
keypad.add(displayArea);
displayArea.setEditable(false);//DEFINE BUTTONS PANEL LAYOUT
buttons.setLayout(new GridLayout( 1, 3, 5, 5));//SET CONTROLS ON BUTTONS PANEL
buttons.add(CalculateBtn);
buttons.add(Amortize);
buttons.add(ClrBtn);
buttons.add(CloseBtn);//ADD ACTION LISTENER
CalculateBtn.addActionListener(this);
ClrBtn.addActionListener(this);
CloseBtn.addActionListener(this);
Amortize.addActionListener(this);
rateTermList.addActionListener(this);//ADD PANELS
pane.add(keypad, BorderLayout.NORTH);
pane.add(buttons, BorderLayout.SOUTH);
pane.add(scroll, BorderLayout.CENTER);
addWindowListener( new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
public void actionPerformed(ActionEvent e)
String arg = lcdLoanAmt.getText();
int combined = Integer.parseInt(arg);
if (e.getSource() == CalculateBtn)
try
JOptionPane.showMessageDialog(null, "Got try here", "Error", JOptionPane.ERROR_MESSAGE);
catch(NumberFormatException ev)
JOptionPane.showMessageDialog(null, "Got here", "Error", JOptionPane.ERROR_MESSAGE);
if ((e.getSource() == CalculateBtn) && (arg != null))
try{
if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 1))
monthlyInterest = interest[0] / (12 * 100);
termInMonths = term[0] * 12;
monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest, -termInMonths))));
lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 2))
monthlyInterest = interest[1] / (12 * 100);
termInMonths = term[1] * 12;
monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest, -termInMonths))));
lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 3))
monthlyInterest = interest[2] / (12 * 100);
termInMonths = term[2] * 12;
monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest, -termInMonths))));
lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
catch(NumberFormatException ev)
JOptionPane.showMessageDialog(null, "Invalid Entry!\nPlease Try Again", "Error", JOptionPane.ERROR_MESSAGE);
} //IF STATEMENTS FOR AMORTIZATION
if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 1))
loopy(7, 5.35);
if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 2))
loopy(15, 5.5);
if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 3))
loopy(30, 5.75);
if (e.getSource() == ClrBtn)
rateTermList.setSelectedIndex(0);
lcdLoanAmt.setText(null);
lcdMonthlyPmt.setText(null);
displayArea.setText(null);
if (e.getSource() == CloseBtn)
System.exit(0);
private void loopy(int lTerm,double lInterest)
double total, monthly, monthlyrate, monthint, monthprin, balance, lastint, paid;
int amount, months, termloop, monthloop;
String lcd2 = lcdLoanAmt.getText();
amount = Integer.parseInt(lcd2);
termloop = 1;
paid = 0.00;
monthlyrate = lInterest / (12 * 100);
months = lTerm * 12;
monthly = amount *(monthlyrate/(1-Math.pow(1+monthlyrate,-months)));
total = months * monthly;
balance = amount;
while (termloop <= lTerm)
displayArea.setCaretPosition(0);
displayArea.append("\n");
displayArea.append("Year " + termloop + " of " + lTerm + ": payments\n");
displayArea.append("\n");
displayArea.append("Month\tMonthly\tPrinciple\tInterest\tBalance\n");
monthloop = 1;
while (monthloop <= 12)
monthint = balance * monthlyrate;
monthprin = monthly - monthint;
balance -= monthprin;
paid += monthly;
displayArea.setCaretPosition(0);
displayArea.append(monthloop + "\t" + calcPattern.format(monthly) + "\t" + calcPattern.format(monthprin) + "\t");
displayArea.append(calcPattern.format(monthint) + "\t" + calcPattern.format(balance) + "\n");
monthloop ++;
termloop ++;
public static void main(String args[])
MORT_RETRY f = new MORT_RETRY();
f.setTitle("MORTGAGE PAYMENT CALCULATOR");
f.setBounds(600, 600, 500, 500);
f.setLocationRelativeTo(null);
f.setVisible(true);
}need help with displaying the textarea correctly and the scroll bar please.
Message was edited by:
new2this2020What's the problem you're having ???
PS. -
Focus in JTextArea (JDK1.4)
hi,
I try to tab in a JTextArea when I use JDK 1.4. But new focus traversal policy in JDK 1.4 does not include JTextArea. Anybody has any idea how to do this: the focus should be on the selected line or the first line by default whenever pressing Tab key into a JTextArea? Thanks anyway.hi,
maybe when you reactivate the browser, you reactivate the site(!) and not the applet.
The applet is only a part of the site and has to be activated, too.
I guess this is the problem.
but i got no idea how to fix this.
sorry.
cu Errraddicator -
Need help using JTextArea to read large file
Hi here is the deal.
I've got a large file (about 12Mbytes) of raw data (all of the numbers are basically doubles or ints) which was formed with the ObjectOutputStream.writeInt/writeDouble (I say this to make clear the file has no ascii whatsoever).
Now I do the file reading on a SwingWorker thread where I read the info from the file in the same order I put it originally.
I need to convert it to string and visualize it on a JTextArea. It starts working. However a one point (56% to be exact since I know exactly the number of values I need to read) it stops working. The program doesn�t freeze (probably because the other worker thread froze) and I get no exceptions (even tough I�m catching them) and no errors.
Does anyone have any idea of what the problem could be?
Thank you very much in advance.
PD: I don�t know if it matters but I'm using ObjectInputStream with the readInt/readDouble functions to get the values and then turning them to strings and adding them to the JTextArea.I can put up the code.
I don't have it with me right now but I'll do it later.
Thank you.
Second. I need to debug a function aproximation that uses a method that has to manage that many numbers. If I don�t put it into a txt and read it there is no way I will know where the problems are, if any. And yes I can look at the txt and figure out problems. It's not that hard.
What I'll try to do is to write directly to regular txt file instead of doing it to the JTextArea.
Thank you for your help and I'll post back with the code and results.
PD: I don't know what profiling is, would you mind telling me? -
Need to make JTextArea scrollbar at top
I've created a JFrameForm using GUI netbeans 5.0
When i created a JTextArea.. then i just put a lot of words inside it, then it'll automatically created a scrollbar there.
The problem i face is when i try to execute it, the scrollbar is at the bottom. How do i make it to start at the top?
Please help.
i've asked at the specific forum, jguru.com , but no one is replying. So i hope any of you can help me about it. Its not that i purposely violate the rule of this forum. I apologize firstly.Hi try like this,
jTextArea1.setText("sdfasdf\nasdfasdf\nasdf\nasdf\nasdf\nasdf\nasdf\nasdf\nasdf\nasdf\nasdf");
jScrollPane1.setViewportView(jTextArea1);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 140, 100, 90));
pack();
jTextArea1.setCaretPosition(0);
regards
Dhinakar -
3.2.2; bc4j; Field needs focus after executequery
I have a rowset that is tied to a table in the database that has some after insert/update triggers. Once I update a record, I commit the record and then execute query to refresh the rowset. Now the fields from this rowset are stretched out over three tabbed panels and the particular field I was on is on the second panel.
How do I send focus back to the field I was editing before the refresh?
Because right now It appears focus is on two fields.
Thanks,
LindaHi ,
follow the below steps::
1. reset the casuser:
NMSROOT/CSCOpx/setup/support > resetCasuser.exe
2.regenerate the SSL certificate :
1) Stop the daemons manager from CLI using
/etc/init.d/dmgtd stop (solaris)
or
net stop crmdmgtd (windows)
2) Backup the following files found in NMSROOT/CSCOpx/MDC/Apache/conf/ssl and
then delete:
server.crt
server.csr
server.key
server.pk8
Under CLI go to "NMSROOT\CSCOpx\MDC\Apache\" and then run ConfigSSL.pl by typed the following
command on CLI.
CSCOpx\MDC\Apache\perl configssl.pl -disable
CSCOpx\MDC\Apache\perl configssl.pl -enable
Then fill the certificate accordingly and restart daemons from CLI using net
start the daemon manager:
/etc/init.d/dmgtd stop (solaris)
net start crmdmgtd (windows)
If above does not help then check the below things:
Make sure files
/opt/CSCOpx/MDC/tomcat/shared/lib/ctm_config.txt and
/opt/CSCOpx/MDC/tomcat/webapps/cwhp/WEB-INF/lib/ctm_config.txt has proper content.
File should not be empty. Check any working server (If any available or just send me these files) for the content, copy and replace
=================
Thanks-
Afroz
***Ratings Encourages Contributors **** -
Hi all,
I am typing a character in a JTextArea (this class is extended from JTextArea and implements KeyListener). I am performing several validations in the keyPressed, keyTyped and keyReleased events. I am checking for a condition in the KeyReleased event. If the condition is true, then the character typed in the keyboard should not be printed in the JTextArea . Is it possible.
The constraint is that the text should not be printed only if the condition in keyReleased method becomes trueHai try this and tell me...
public void keyReleased(KeyEvent e){
String []s = getValue();
/* Naga */
System.out.println(" inside keyReleased");
if (s!=null && s.length>rows)
System.out.println("setting text");
e.consume();
//updateUI();
//e.setKeyCode(KeyEvent.VK_CAPS_LOCK);
//invalidate();
return;//add this line
} -
Moving the Focus with the TAB key in a JTextArea Component
Dear Friends,
I have exhausted all options of moving focus from JTextArea to next component. I have also tried all suggestions available in this forum. But i'm not able to solve my problem. Can any one help me.
Thanx in advance.I had the same problem before. Here is what i did.
JTextArea txtArea = new JTextArea(2,15);
Set forwardTraversalKeys = new HashSet();
forwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
txtArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,forwardTraversalKeys);
Set backwardTraversalKeys = new HashSet();
backwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));
txtArea.setFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardTraversalKeys);
JScrollPane scrollPane = new JScrollPane(
txtArea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// the scrollbar of the JScrollPane is focusable that's why it requires
// another TAB key to transfer the focus.
scrollPane.getVerticalScrollBar().setFocusable(false); -
How to create a cell column with JTextArea in JTable
I am developing an Application using Java Swings. I need to use JTextArea in my JTable. I need the code to do so. I also want to show the scrollbars in the JTextArea.
Any efforts in this regard would be of great help. Thanks in advance.
Thanks
Alaguhave a look at
http://forum.java.sun.com/thread.jsp?forum=57&thread=134412 -
hi
i don't get focus on checkbox.I need focus on the checkbox not on the text with it.what should i do?i sending my code please help me.
public class SECOND extends javax.swing.JFrame {
public SECOND() {
initComponents();
setSize(500, 500);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jCheckBox1 = new javax.swing.JCheckBox();
jButton1 = new javax.swing.JButton();
getContentPane().setLayout(null);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
getContentPane().add(jTextField1);
jTextField1.setBounds(70, 60, 170, 21);
getContentPane().add(jCheckBox1);
jCheckBox1.setBounds(80, 120, 70, 15);
jButton1.setText("OK");
getContentPane().add(jButton1);
jButton1.setBounds(100, 170, 90, 25);
pack();
public static void main(String args[]) {
new SECOND().show();
private javax.swing.JButton jButton1;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JTextField jTextField1;Hi,
There's a number of ways to deal with this problem:
1. Write an anonymous class that overides paintComponent() in the JCheckBox.
2. Write an explicit class that extends JCheckBox and overrides paintComponent().
3. Write a class that extends BasicCheckBoxUI and overrides paintFocus(). Tell the UIManager to use this class for all JCheckBoxes.
Which method should you use?
1 if there is only one JCheckBox in the whole application that you wish to have this functionality. (I personally prefer not to use anonymous classes).
2 if there is a number of places you need this behaviour.
3 If you would like every instance of JCheckBox (even its subclasses) to have this functionality.
Hope that helps,
Muel. -
JTextArea as a command line in an application
I need to have a 'command line' area in an application I develop. I have the following JTextArea in my JFrame:
JTextArea CommandArea = new JTextArea("� ");I want to make only the text behind the prompt "� " editable. If the user tries to type a command at an other position the caret should jump to end of the JTextArea and insert it there.
Any ideas?I think you need to extend JTextArea something like
class PTextArea extends JTextArea {
and put the required functionality in that by handling events on this.
any good
cheers -
JTextPane & JTextArea Control Handling
Hello...
I have created chat application. At client side i take applet in that The chat is dispalyed in JTextPane in different colors. Also i have taken JTextArea & button to send message to other end. But the problem is that when chat message is receives from remote end it is shown in JTextPane & if at same time user is typing message in JTextArea then focus is lost from JTextArea to JTextPane. This action prevents user from writing he has to set focus on JTextArea again & again.
The code is
StyledDocument doc = (StyledDocument)jtp.getDocument();
doc.insertString(doc.getLength(), "\n"+oprName+": "+matter, style2); Help plz.....This is a bit of a guess but you may well find that my suggestion in this thread (apply it to your display component rather than the input component) fixes it,
http://forum.java.sun.com/thread.jspa?threadID=5114287
If not then you should be able to follow the source code from setText() to see what's grabbing the focus. -
hi all,
My question is how can i gain a focus on JTextarea when mouse click on it.
any hits are welcome.Thanks in advance.
Message was edited by:
cocoonwls
Message was edited by:
cocoonwls
Message was edited by:
cocoonwlsI am not sure why you would want focus on a label, but if you do, add the jlabel to a mouselistener and when you click, write, "jlabel.requestFocus()".
Maybe you are looking for
-
Ipod connection to 2014 Toyota Camry
Having issues connecting Ipod touch (1st gen) to 2014 camry via usb. supposed to be compatible, says "ipod authorization unsucessful" , any ideas?
-
Resolution/Sidebars From Motion to FCP
Hey guys, Absolute noobie here, so please bear with me; I am following the tutorials on the apple FCS DVD and am onto the Motion section, i have done the whole 'send to montion' on the "Blue Horizon" bit and I've just done command save and popped bac
-
I can't get photos on my Nano....
I select the folders and everything, it even says "Optimizing for Ipod", but it always says that there isn't enough room for the photos. I have 10MBs of photos, and cleared 30MBs of space for them, and it still says there isn't enough room for them.
-
Hi, I have written a small C++ code which will load a JDBC Driver and connect to the database. The code initially Loads the JVM & than connects to the Database. When i tested the code with Boundscheket I found a conciderable amount of memory leak & a
-
Able to receive but not to send emails
Purchased macbook pro, ipad & iphone at xmas ... experiencing ame problem with all of them. I can received emails okay via mobile me, yahoo, gmail but 90+% of emails I send are not received by recipient and I get bounce back SMTP error messages. (I d