Urgent: Setting character limit for JTextArea
Hi, I am newbie to java swing and I have a question.
I need to set a limit of 2000 characters that can be typed in a text box(JTextArea). How do I do that?
Thanks for the help.
Here is the sample code to do this using KeyListener. This is crude way but is an easy way for newbie's. Using documents is more sophisticated way.
<code>
public class LimitedCharsTest extends JFrame {
private JTextArea limitedCharTextArea = new JTextArea();
public static final int MAX_CHARS = 10;
public LimitedCharsTest() {
JScrollPane scrollPane = new JScrollPane(limitedCharTextArea);
this.getContentPane().add(scrollPane);
this.setSize(200,200);
limitedCharTextArea.addKeyListener(new TextAreaKeyListener());
this.setVisible(true);
public static void main(String[] args) {
LimitedCharsTest limitedCharsTest1 = new LimitedCharsTest();
private class TextAreaKeyListener extends KeyAdapter {
public void keyTyped(KeyEvent ke) {
String taContent = limitedCharTextArea.getText();
if(taContent != null && taContent.length() >= MAX_CHARS)
ke.consume();
</code>
Similar Messages
-
Line limit for JTextArea - Urgent
Hi All,
I would like to have 80 character limit for each line displayed in JTextArea. The linewrap along with wordwrap have been enabled for JTextArea but that solves a part of the problem. The no. of characters that can be entered per line depends on the width of the component and the font size. For this component there is no upper limit for the total no. charaters that can be entered. Basically, it supports text editing feature(cut, copy, paste). One way it could have been done by fixing the width of component so that it could accomodate only 80 characters, but again the factors like screen resolution, font's advance width keeps changing. I tried with overriding insertString() of PlainDocument class, but didn't know how to wrap the characters after 80 position to next line if text is inserted in the middle of a line. At the same time the whole text needs a reformatiing. Same behavior is desirable while doing cut/paste operations.
A hint or sample code will be highly appreciated as it has been a long time I am looking to solve this problem.
Thanks
Ritwick.You are correct it is not easy to override the default behaviour of the JTextArea. So my suggestion is to use a monospaced font. The code would then be:
JTextArea.textArea = new JTextArea( "some text", 10, 80 );
textArea.setFont( new Font("monospaced", Font.PLAIN, 12) );
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
JScrollPane scrollPane = new JScrollPane( textArea );
scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );If using a monospaced font is not possible, then please explain why wrapping at exactly 80 characters is so important, maybe there is a different approach to take. -
Character Limit for PDF Bookmark
What is the maximum number of characters that Acrobat allows for a PDF bookmark?
Please post what you find with BB10 re: the hard limit or character limit for Contact Notes. If BB10 simply carries over their existing limits to their new platform (which is very stingy), then this could be a deal breaker. I'd be VERY disappointed but definitely NOT surprised.
By the way, I bought a 3rd party program that syncs BB with Outlook and any other program and it's called "CompanionLink" and it works with BB Desktop seamlessly. You don't even know it's running as you still sync using the native BB desktop. CompanionLink increases the hard limit that BB has set for Contact Notes, Tasks, etc. However, there is still a limit. So instead of getting maybe a 1/4 to 1/2 page of notes (on a word doc) you get almost a full page. -
Can v set credit limit for a vendor? if so, how?
can v set credit limit for a vendor? if so, how?
Hello
the two replies are correct that the redit limit is always used for customers. but i can give you the scenario as per the request and Amrita please correct me if i am making something wrong.
as per vendors there are three to four vendors are available for buying a material. we are not using quota arrangement but we just distribute the order based on the situations. the order is given to a vendor who is quoting low price, giving the required quality and quantity and supplying as per our need. there is one more criteria for choosing this vendor. the outstanding balance for this vendor should not cross some limit.
the limit may be based on negotiations and the some contracts' terms and conditions.
the solution for this may be that there should be one report where you can see how much we owe to each vendor. this could be possible only when we know the Vendor g/l account and the corresponding balances.
i think i have cleared the credit idea as well as given the solution. please reward if found it helpful. -
Is there a character limit for a field in CrystalReports?
Is there a character limit for a field in CrystalReports?
Hello,
I'm trying to display a long text (+100.000 characters) stored in a MySql database in CrystalReports but CR is not showing the complete text. Is this because there is a length limit for fields in CR?
Thanks,
Eddy G.This is not a great answer, but you can base your report on a SQL Command, then use something like this for the command(MS SQL):
select
case when length(table.field) > 65535
then substring(table.field,1,65535)
else table.field end as field_part1,
case when length(table.field) > 65536+65535
then substring(table.field,65536, 65535)
when length(table.field) between 65536 and 65536+65535
then substring(table.field,65536, length(table.field)-65535)
else '' end as field_part2
from table...
Then in the report, display both fields where you want the BLOB data.
HTH,
Carl -
HT201991 What is the character limit for length for video or song reviews?
What is the character limit for length for video or song review?
One other thing I found... It was still doing the spinning clock and locking up, but it took a while after boot for the problem to crop up.
I pulled the media card and found that there was a media sync folder under Blackberry\System that had some files in there that were pretty big. The artwork file was over 150MB and some other files were largish.
I deleted the entire media sync folder and now it seems to be behaving itself. No more spinning clock and it seems to be slowly returning to normal. (Besides all the messages it deleted during the whole process)
If anyone else runs into this I would say you should clean the folder off the media card along with disabling the sync. Seems the BB still reads that folder and processes it if present. -
Control/set a limit for file attachment
Hello,
I would like to know if there is a way to control/set a limit for file attachment in Workbench ES. e.g. Assign Task > Attachments & Notes.
Can you please advise.
Thanks,
Han DaoNo. You would have to customize Workspace to do that.
Jasmin -
As a webservice client, how to set character encoding for JAX-WS?
I couldn't find the right API to set character encoding for a webservice client. What I did is
1, wsimport which gives me MyService, MyPortType...
2. Create new MyService
3. Get MyPort from MyService
4. Call myPort.myOperation with objects
Where is the right place to set character encoding and how to set it? Thanks.
Regards
-Jiaqi GuoThe .js file and the html need to have the same encoding. If
your html uses iso-8859-7, then the .js must also use that. But if
the original text editor created the .js file using utf-8, then
that is what the html needs to use. -
Is there a character limit for iTunes U course postings when viewing in iOS app?
I have created a course in iTunes U using the web interface, but when I view the course on my iPad it doesn't show the entire post. Is there a character limit in the app or something for what will display?
To make things even stranger, I went back to the course editor in my browser and saved it again (effectively re-posting it) and when I restarted the iTunes U app in iOS the post was cut even shorter! I'm using an iPad 3rd gen with iOS 6.0.1.No, there is no workaround. You would need to find a downloadable copy of old apps.
-
Can we get a character limit for the subject line?
Some of the more annoying posts place the entire story in the subject line.
(e.g. http://forums.ni.com/ni/board/message?board.id=170&thread.id=334536&jump=true)
The problem is that the edit window when replying blows the margins, making it wider than the screen.
I would think that e.g. a 132 character limit would be sufficient for titles. If anything posted from the newsgroup exceeds that, it could be truncated.
LabVIEW Champion . Do more with less code and in less time .I agree with Christian,
It seems that some people want to describe the entire issue in the title instead of providing a synopsis.. -
How to Set Item limit for Picture library Slideshow webpart in SharePoint 2013
Picture library Slideshow webpart is using the default view "All Pictures" and if I set a filter condition in the view, the images are displaying based on it but if I set an Item limit as "5" or any number in the "All Pictures"
view it is not reflecting in the slideshow webpart.
Any suggestion would be a great help as the users want to see only the latest 5 images in the slideshow webpart.
Thanks & regards,
AshaI don't think so there is any way to set a item count limit on Picture Library Slideshow web wart.
Web Part setting only allows to provide library and View, In List view also you can only set Item Limit to be shown on the 'List View'. Slideshow web part take all the items in the list and show, view is only used to provide which field needs to be shown.
There could be 2 options:
- Write a JavaScript to limit the count, and in the view add Sorting by 'Created' date. You can get some example on how to modify "Library Slideshow web part" javascript here: http://blog.vgrem.com/2013/04/27/beyond-the-slideshow-web-part-capabilities-in-sharepoint-2010/
This link does not have solution of what you want, but it gives a very well idea on what you can look and modify. It will not be that straight forward for sure.
- Create a custom webpart, it could be a easier approach. As there are many slideshow Javascript library present, and through code you will just need do a query and pull data from library with required number of items to be shown.
get2pallav
Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you. -
How I set character encoding for everypage and alway?
I use Thai window 874 open the page when I select some website it contain Thai then click open new tab it change to western windows 1252. It can not display Thai. I must set character encoding to Thai windows 874 everytime.
Try this:
Prefrences -> Content -> Fonts & Color -> Advanced
At the bottom, choose your Encoding. -
How to set the limit for the warning 'running out of disk space'
I am wondering if there's a way to set the number of GB before I get the system warning 'running out of disk space'.
I saw this question asked in 2010 and it did not get an answer. It was archived so I am asking again. I know how to monitor the available space on my startup disk, and how to empty the trash to clear up disk space. I am looking for an OS X setting that I can change.My guess is that you want to lower the limit. IMHO I think the limit is alreay too low.
If you are seeing this warning regularly then your disk is severely overfull and needs to be replaced with a larger one.
Running the free space low eenough to get the warning greatly increases the chances for disk corruption. Once the disk gets corrupted then then next thing that happens is data lose.
You have a serious problem with your Mac that should be dealt with immediately.
Backing your data up would also be a good idea if you are not already doing that.
Allan -
Cash Journal : How to set the limit for maximum payment of 20000
Hi Gurus,
Please tell me how can i set the maximum payment limit of 20000 in cash journal?
Please revert asap.
Thank YouHi
Amount Limit
Use
You use these functions to define limit values for the FI cash journal; where these limits are reached and exceeded, the user is prompted (in an information dialog box) to run certain activities. The check is always performed in the first local currency of the company code.
In the countries of the European Union, these functions are used to draw attention to the legal requirement for identifying the payer (money laundering law § 3 para. 1).
Activities
Company code:
You do not have to enter a company code. The entry is then valid for all company codes within a client that use the currency specified as the first local currency.
Currency:
Each amount must be specified by the classification of the currency. If you specify a company code, the currency of the company code is entered in the currency field and you cannot change this.
Date and amount:
The amount limits are defined time-dependent ("Valid From").
In addition to the above
Input your company code,Currency,Valid from and the amount limit
Good Luck
Hari -
Do we have any option to set time limit for report execution
Hi Experts,
Please Could any one clarify is there atime limit to set for report execution and if it crosses the limit it wud not display a data,
Thanks in advance
NityaHi,
Basis should be help you in timeout settings on various cases. Time out setting while execution from portal is there.
Regards,
Akshay
Maybe you are looking for
-
iTunes told me to delete my backup folder when I was having problems syncing my phone to my computer. After that it wouldn't work at all. After trying and trying I deleted iTunes when it said "iTunes could not back up iPhone because the backup could
-
Windows Update Stalls When Running in Windows 7/Windows Virtual PC/Win XP_ Mode
Hi This is Bob in Tallahassee. Can anyone please help. I installed Win7 Pro on a newly built PC and then Windows Virtual PC/Win XP Mode. When I try running Windows Update in the XP mode window, it keeps cycling "searching for updates" and never rea
-
Proxy Problem The proxy server is refusing connections
I run Windows XP. I did have a Cybot backdoor Activity attack intercepted by Norton Internet Security and I used the Norton NPE to remove it from the computer. I do not know if this caused the proxy problem or not. There is no proxy problem connectin
-
Playing songs from external hardrive
Hi, my toshiba laptop finally died earlier this week so i decided to get an apple because of the luck i had with our desktop at home, despite it costing more than i thought, since it no longer comes with appleworks, but back to my problem. I want itu
-
Vbox, mount share file can't work normal
hi,everyone. i use virtualbox and has install virtualbox-additions. i exec "pacman -Syu" today and then i find that when i mount share file ,it doesn't work normal. i exec "mount -t vboxsf share /mnt" ant "cd /mnt" then "ls " it show that a.c .but w