Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Text component and button problem

  Asked By: Anita    Date: Apr 14    Category: Java    Views: 792
  

1) Why does everytime I press TAB key on JTextArea, the cursor
doesn't move to next focusable component? Can I fix this problem?
What method should I use?

2) If I have this code :

JTextField myText = new JTextField(15)

I thought myText can only accept 15 character, but I was wrong. Can I
make myText to receive only 15 chars, so after I typed 15 chars, the
16th char won't be displayed?

3) Is it possible to create a textfield that receives only numeric? I
try to use JFormattedTextField :

DecimalFormat formatter = new DecimalFormat("##########");
JFormattedTextField numericText = new JFormattedTextField(formatter);
numericText.setColumns(10);

But when I type "012345", it becomes "12345". I still need the "0". I
tried to use different formatter :

DecimalFormat formatter = new DecimalFormat("0000000000");

but when I type "012345" again, it becomes "0000012345". I don't need
the first 4 "0".
Can anybody help me with this one?

4). About JButton. Can I create a JButton which its caption displayed
in 2 (or more) rows?
This code :
JButton myButton = new JButton("1st row\n2nd row");
didn't recognize the line separator, so the caption is "1st
row2ndrow".

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Sally Pierce     Answered On: Apr 14

For #3, tell it to get the length of the String (length or size, I
forget). Then do something like:

String str="";
for(int i=0; i<num.length; i++)
{
str+="0";
}
DecimalFormat formatter = new DecimalFormat(str);

It's not very efficient, but it should work.

 
Didn't find what you were looking for? Find more on Text component and button problem Or get search suggestion and latest updates.




Tagged: