| JTextArea size limitiing question ... |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- Using JComponent.getGraphics() in Swing for incremental paintingHello,
I have read many posts and articles saying "don't ever use
getGraphics() in Swing JComponents... always use paintComponent()!" I
understand the motivation for such statements: the paintComponent()
method should be used to implement painting, in order to ensure
correct behavior in all situations.
However, my question is: is it OK, from within an event handler, to
paint using getGraphics() PURELY AS AN OPTIMIZATION, AS LONG AS
paintComponent() does the right thing?
An example:
class MyComponent extends JComponent
{
ArrayList thingsToPaint=new ArrayList();
public void mySwingEventHandler(SomeEvent e)
{
//update thingsToPaint so that paintComponent
//works correctly
thingsToPaint.add(somethingNewToPaint);
//try painting directly
Graphics g = getGraphics();
if(g != null)
{
//we have a graphics, so paint the new
//thing directly.
somethingNewToPaint.drawOn(g);
g.dispose();
}
else
{
//No graphics object available... so just
//call repaint().
repaint();
}
}
public void paintComponent(Graphics g)
{
//paint everything
int i, size = thingsToPaint.size();
for(i=0; i < size; ++i)
{
((ThingToPaint) thingsToPaint.get(i)).drawOn(g);
}
}
};
I actually have a good reason for doing this. I am writing a simple
image manipulation program, and I need to implement a rectanglar
selection facility. In order to accomplish this, I need to listen to
mouseDragged events and repaint the rectangle on the image at each new
position. Swing forces you to re-paint the entire image each time
(i.e. no incremental updates), which is annoyingly slow for this
particular problem. And I don't want to turn off double buffering.
If I use getGraphics() directly (as in the example above), I can just
update a tiny section of the image, and it is blindingly fast and
smooth. I have tested this, and it works wonderfully in my limited
tests. But I don't want to do it if it will be problematic down the
line.
So, is it OK to use getGraphics() if the full repainting functionality
is available in paintComponent()? Or is there some other reason not to
use getGraphics()?
Thanks,
Mike Carrato
- 1
- Ease of Development in Enterprise JavaBeans TechnologyEnterprise JavaBeans (EJB) technology is a J2EE technology for developing
business components in a component-based, enterprise Java application. There's
a new article available that addresses an overview of EJB technology
and information on developing an Enterprise Bean with EJB.
Read about it here:
http://java.sun.com/developer/technicalArticles/ebeans/ejbease/index.html?ssobm=ng
- 3
- Q: How to organize unit testingIf I have a custom library formed by a package hiarachy build over the
years, what is the usual way of organizing JUnit testing?
Placing a suite in every package which wraps test case classes is messy
and pollutes the library when deployed as a jar.
I see two possebilites, either separate the tests by the use of
preprocessor build directives (but Java has none right?) or create a
mirror of the library package structure where only the tests live. Which
is the common practice and what problems should I look out for?
Thanks in advance,
Casper
- 3
- java/61407: jdk14 port aborts making html32dtd
>Number: 61407
>Category: java
>Synopsis: jdk14 port aborts making html32dtd
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: freebsd-java
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Thu Jan 15 21:20:03 PST 2004
>Closed-Date:
>Last-Modified:
>Originator: Alan Batie
>Release: FreeBSD 4.8-STABLE i386
>Organization:
RainDrop Laboratories
>Environment:
System: FreeBSD pyrex.batie.org 4.8-STABLE FreeBSD 4.8-STABLE #1: Sun Nov 9 03:18:36 PST 2003 email***@***.com:/usr/src/freebsd/src/sys/compile/PYREX i386
Latest jdk14 port using patchset 6:
# $FreeBSD: ports/java/jdk14/Makefile,v 1.71 2004/01/14 21:21:52 glewis Exp $
>Description:
>How-To-Repeat:
cvsup (this morning about 5:30 or so PST)
cvs update ports
cd ports/java/jdk14
make
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
>>>Recursively making html32dtd html32dtd @ Thu Jan 15 20:56:04 PST 2004 ...
gmake[4]: Entering directory `/usr/src/ports/java/jdk14/work/j2se/make/javax/swing/html32dtd'
gmake make-html32dtd
gmake[5]: Entering directory `/usr/src/ports/java/jdk14/work/j2se/make/javax/swing/html32dtd'
/bin/mkdir -p /usr/src/ports/java/jdk14/work/control/build/bsd-i586/tmp/javax/swing/html/dtbuilder/obj
/bin/mkdir -p /usr/src/ports/java/jdk14/work/control/build/bsd-i586/tmp/javax/swing/html/dtbuilder/dtdgenclasses
rm -f /usr/src/ports/java/jdk14/work/control/build/bsd-i586/tmp/javax/swing/html/dtbuilder/.classes.list
if [ -s /usr/src/ports/java/jdk14/work/control/build/bsd-i586/tmp/javax/swing/html/dtbuilder/.classes.list ] ; \
then /usr/src/ports/java/jdk14/work/control/build/bsd-i586/bin/javac -J-XX:ThreadStackSize=768 -J-Xms64m -J-Xmx256m -J-Xmaxf1 -classpath /usr/src/ports/java/jdk14/work/control/build/bsd-i586/classes -bootclasspath "/usr/src/ports/java/jdk14/work/control /build/bsd-i586/lib/jce.jar:/usr/src/ports/java/jdk14/work/control/build/bsd-i586/lib/jsse.jar" -sourcepath "/usr/src/ports/java/jdk14/work/control/build/bsd-i586/gensrc:../../../../src/solaris/classes:../../../../src/share/classes" -d /usr/src/ports/jav a/jdk14/work/control/build/bsd-i586/tmp/javax/swing/html/dtbuilder/dtdgenclasses -source 1.4 \
../../../tools/dtdbuilder/PublicMapping.java ../../../tools/dtdbuilder/DTDParser.java ../../../tools/dtdbuilder/DTDInputStream.java ../../../tools/dtdbuilder/DTDBuilder.java ; \
fi
rm -f /usr/src/ports/java/jdk14/work/control/build/bsd-i586/classes/javax/swing/text/html/parser/html32.bdtd
(/usr/src/ports/java/jdk14/work/control/build/bsd-i586/bin/java -ms16m -mx64m \
-classpath "/usr/src/ports/java/jdk14/work/control/build/bsd-i586/tmp/javax/swing/html/dtbuilder/dtdgenclasses:" \
-Ddtd_home=../../../tools/dtdbuilder/dtds \
dtdbuilder.DTDBuilder html32 > /usr/src/ports/java/jdk14/work/control/build/bsd-i586/classes/javax/swing/text/html/parser/html32.bdtd) || exit 1
[Parsed DTD html32 in 197ms]
Abort trap (core dumped)
gmake[5]: *** [/usr/src/ports/java/jdk14/work/control/build/bsd-i586/classes/javax/swing/text/html/parser/html32.bdtd] Error 1
gmake[5]: Leaving directory `/usr/src/ports/java/jdk14/work/j2se/make/javax/swing/html32dtd'
gmake[4]: *** [swing-html32dtd] Error 2
gmake[4]: Leaving directory `/usr/src/ports/java/jdk14/work/j2se/make/javax/swing/html32dtd'
gmake[3]: *** [html32dtd] Error 1
gmake[3]: Leaving directory `/usr/src/ports/java/jdk14/work/j2se/make/javax/swing'
gmake[2]: *** [all] Error 1
gmake[2]: Leaving directory `/usr/src/ports/java/jdk14/work/j2se/make/javax'
gmake[1]: *** [all] Error 1
gmake[1]: Leaving directory `/usr/src/ports/java/jdk14/work/j2se/make'
gmake: *** [j2se-build] Error 2
*** Error code 2
Stop in /usr/src/ports/java/jdk14.
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 3
- Running a bat file from a Tomcat servlet using the exec commandI cannot get a Tomcat servlet to execute a Windows Bat file.
Is there a particular setting in the catalina.policy file that I need
to change?
Here is a code snippet of the call:
Runtime load = Runtime.getRuntime();
Process process = load.exec("cmd.exe /c start copyFiles.bat", null,
new File("C:\\Tomcat 5.0\\webapps\\myApp\\files"));
Thanks for any help.
-Chris
- 3
- have troulbe when learn java tutorial's network socket partHi everyone:
Try fewest word: from Java Turotial->Custom Networking->All About
Sockets->Reading from and Writing to a socket, the following program:
import java.io.*;
import java.net.*;
public class EchoClient {
public static void main(String[] args) throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
echoSocket = new Socket("taranis", 7);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
echoSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: taranis.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to: taranis.");
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("echo: " + in.readLine());
}
out.close();
in.close();
stdIn.close();
echoSocket.close();
}
}
But it says "Don't know about host: taranis". If I change it to my
computer's name, it says "Couldn't get I/O for the connection to:
taranis.";
So how can I open echo service on a computer? Thanks.
- 4
- Best tool/methodology/practise for Java code protection ?I'm writing a commercial engineering library and I am very uneasy about
the apparent ease with which Java binaries are reverse engineered.
I would like to hear from anyone who uses a tool (commercial or
otherwise) for protecting their IP (in the form of source code) when
they distribute their binaries. For obvious reasons, I am not interested
in hearing from any vendor (or employee thereof) who will naturally be
biased in favour of their offering. I will be most interested in hearing
from people who have actually deployed binaries out there in the field,
and are happy with their obfusucation/encryption tool, methodology or
policies etc.
MTIA
- 7
- Transmitting strings via tcp from a windows c++ client to a Java serverHi all,
We have a C++ client which runs on Windows and that needs to transmit
char* / wchar* strings to and from a Java server.
The client should correctly handle both 'standard' languages & east
Asian
languages (i.e. using wchar).
Now, I'm sure there is a best practice for doing so , I just haven't
found it yet :-)
My best bet would be always encoding the string in UTF-8 before
sending
it via the net, but I could be wrong.
Your help will be highly appreciated.
Thanks,
Gilad
- 7
- Packaging Maven 2 - shipping binaries for bootstrapping.-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi debian java folks, hi mentors,
I'm posting this to mentors, too, because the problem described below is
not only about maven2 but about a general problem with bootstrapping
circularely depending packages.
More news on packaging maven2. I was able to built some more
dependencies of maven2 as debian packages. Now, I reached a point where
I need a hint:
Maven-components is built with a custom bootstrapping shellscript which
builds some core components of maven2 and then builds maven2 with the
help of the bootstrapped libraries. Maven-repository-metadata built
during the bootstrapping depends on a modello-test. modello-test itself
depends on maven-artifact. Modello test is a seperate package which
shall be built seperately from maven2. Because maven-repository-metadata
and maven-artifact are built using the bootstrapping script in one build
run there is a circular dependency. Think A -> C, C -> B where A and B
are in the same source package, C is in another.
I see two ways of breaking this:
First, ship modello as binary jar file with the first source tarball of
maven2 until maven2 is in the archives and can build modello. The
license of modello allows the binary contribution. The later versions
can be built with the packages from the archives then.
Second option: Split maven-components into several packages. This will
be not very easy because of the sophisticated bootstrapping of maven2.
The process buils some bootstrapping code using a shellscript which
build a level 2 bootstrapper which builds the maven core which builds the
maven plugins. Event then, marven-artifact must be shipped as a separate
source package because of the dependencies described above.
Any objections against using the first method to get an initial version
of maven2 into the archives?
- -billy.
- --
Philipp Meier - email***@***.com
A: Because it breaks the logical sequence of discussion
Q: Why is top posting bad?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFEBsFcZo1qZ89k76URAmr1AJ40B4RYzOuAqABmpLIO06i3eNDlEgCeKGHb
PY1IMs2WCmxCclyrxJUIbRQ=
=iZFw
-----END PGP SIGNATURE-----
--
To UNSUBSCRIBE, email to email***@***.com
with a subject of "unsubscribe". Trouble? Contact email***@***.com
- 7
- How to find a whether a method is used by particular thread or not?Hi,
I am not familiar with Thread in java.I have one scenario.Let
me explain conceptually.
suppose i have one method
public synchronised void m1()
{
....
}
and another
public synchronised void m2()
{
......
}
Suppose i have two threads T1,T2.
Now what i want is , if T1 is accessing m1() i don't want T2 to access
m2().Please give me some idea how to do this.Which methods i can use
to identify this?
I will be very thanlful ,if somebody can exaplain me this with an
example programmatically.
Regards,
Siva
- 8
- JTable cell editor update several columnsI have a JTable with multiple columns line
let's say : name, cat, subcat, lang
I would like a cell editor on name ;cat , subcat and lang read only
when I edit name whenever I choose a mame that belongs to
cat,subcat,lang the cat,subcat,lang cells are updated .....
tanks a lot
patrick
jdk1.6.0_02/linux
- 8
- platform default charsetHello,
How can I change the platform's default charset used by a VM ?
I am talking about the charset used by String methods such
byte[] getBytes()
Encodes this String into a sequence of bytes using the
platform's default charset, storing the result into a new byte array.
Thank you,
Christophe
- 12
- A grammar lesson for EdEd wrote:
> Yes, I do! The fact that I got the 5-start ratings on my postings
> explaining how you was rude to me, makes me to kind of trust the
> google ratings!
(To readers of m.e.l.e: this is a perfect example of how NOT to write
English.)
(P.S. I know I shouldn't do this, but it is just too fun to pass up ;-))
Several comments to explain about why this is not proper grammar:
In English, the word `was' indicates the past participle of `to be' in
the third person singular form /only/. The relevant past participle
(here, we need to be in second person, which corresponds as well to all
plural forms) that you are looking for is `were'.
The construction `to make one' is not followed by the word `to'; what
you need to do is drop that word from the following infinitive.
There is no word called `google' (there is a `googol', as in 10^100). If
you are referring to the company with that name, then your
capitalization should reflect that, as a proper noun [*]: `Google'.
Semantically, that classifies all of your sins; however, your choice of
words is not the most appealing in the world.
`To get' is very slangy, and, seeing as Usenet expects a certain level,
of professionalism, the better verb is `to receive'.
I know of no rating that uses `starts'; are you looking for `star'?
`5' should not be written as a digit (as well as other numbers less than
ten), it is better to use `five' in this case.
On forums, the term `posting' should be eschewed in favor of the word
`post' (shorter noun, and I dislike gerunds as well).
Finally, usage of exclamation points is highly disregarded in Usenet
posts, as it places others' impressions of you as roughly equivalent to
a loud-mouthed twelve-year old kid. Your continual usage of vulgar
language and poor grasps on the basic points of politeness also add to
the impression of a brat.
[*] Well, in recent times, companies have fallen in love with the
non-traditional forms of capitalization, preferring such proper nouns as
`iPod'. The best rule of thumb to follow is to use the official
capitalization rules of the company owning the trademark.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
- 15
- Unchecked call hashmapWhat is this with javac -Xlint??
warning: [unchecked] unchecked call to put(K,V) as a memb
er of the raw type java.util.HashMap
headers.put(key,val);
^
- 16
- JMS memory footprint sizeAnyone know what the memory footprint of JMS is?. I am trying to work
out if it is too "heavyweight" for use in a thin client.
tkx
|
| Author |
Message |
Charles Morison

|
Posted: 2006-3-24 12:43:00 |
Top |
java-programmer, JTextArea size limitiing question ...
I'm using a JTextArea within a JScrollPane within a JViewPort. I am
using the JTextArea to mimic a HyperTerminal like terminal emulation
interface. When I set up the JTextArea I specify the viewable rows and
columns, but since it is inside the JScrollPane it obviously can grow
"infinitely" large (and eventually throw a heap memory exception). My
desire is to not allow this, but was hoping that there was something
within Java itself to passively limit the size of the JTextArea.
Currently I use it to receive diagnostics (through a serial
communications port) from an embedded device, so during testing I could
conceivably let this run for several days (which will most certainly
induce a heap memory exception). I am also logging all of the
diagnostics to a file so I have no need for the JTextArea to grow
"infinitely" large.
So is there a way to passively limit the ultimate size of a JTextArea
that I am missing or do I have to actively determine its size and trim
it down some how (and if so, any suggestion on how to delete "old" data
in a JTextArea)?
Thanks, in advance, for any help.
|
| |
|
| |
 |
Charles Morison

|
Posted: 2006-3-24 12:46:00 |
Top |
java-programmer >> JTextArea size limitiing question ...
I'm using a JTextArea within a JScrollPane within a JViewPort. I am
using the JTextArea to mimic a HyperTerminal like terminal emulation
interface. When I set up the JTextArea I specify the viewable rows and
columns, but since it is inside the JScrollPane it obviously can grow
"infinitely" large (and eventually throw a heap memory exception). My
desire is to not allow this, but was hoping that there was something
within Java itself to passively limit the size of the JTextArea.
Currently I use it to receive diagnostics (through a serial
communications port) from an embedded device, so during testing I could
conceivably let this run for several days (which will most certainly
induce a heap memory exception). I am also logging all of the
diagnostics to a file so I have no need for the JTextArea to grow
"infinitely" large.
So is there a way to passively limit the ultimate size of a JTextArea
that I am missing or do I have to actively determine its size and trim
it down some how (and if so, any suggestion on how to delete "old" data
in a JTextArea)?
Thanks, in advance, for any help.
|
| |
|
| |
 |
Rhino

|
Posted: 2006-3-24 13:03:00 |
Top |
java-programmer >> JTextArea size limitiing question ...
"Charles Morison" <email***@***.com> wrote in message
news:RNKUf.6287$email***@***.com...
> I'm using a JTextArea within a JScrollPane within a JViewPort. I am using
> the JTextArea to mimic a HyperTerminal like terminal emulation interface.
> When I set up the JTextArea I specify the viewable rows and columns, but
> since it is inside the JScrollPane it obviously can grow "infinitely"
> large (and eventually throw a heap memory exception). My desire is to not
> allow this, but was hoping that there was something within Java itself to
> passively limit the size of the JTextArea.
>
> Currently I use it to receive diagnostics (through a serial communications
> port) from an embedded device, so during testing I could conceivably let
> this run for several days (which will most certainly induce a heap memory
> exception). I am also logging all of the diagnostics to a file so I have
> no need for the JTextArea to grow "infinitely" large.
>
> So is there a way to passively limit the ultimate size of a JTextArea that
> I am missing or do I have to actively determine its size and trim it down
> some how (and if so, any suggestion on how to delete "old" data in a
> JTextArea)?
>
I'm not sure if there's a direct way to limit the capacity of a JTextArea.
I'd be a little surprised if there was and don't see anything like that in
the API. But maybe I just didn't look carefully enough.
However, a less direct approach seems very possible. One of the methods that
JTextArea inherits from JTextComponent is getText(); it returns a String
that has the contents of the JTextArea. Therefore, if your JTextArea is
called myTextArea, myTextArea.getText().length() will tell you how many
characters you have in your JTextArea.
You could use a Caret Listener to detect when the caret (cursor) for the
JTextArea indicates that the JTextArea is over a certain size; if that
happens, you can use the select() method of JTextComponent to find a desired
part of the JTextArea - the first 100 characters, for example - and then
remove those characters, presumably after writing them to somewhere
permanent if you still want the information in them. The easiest way to
remove them from the JTextArea would appear to be the cut() method of
JTextComponent.
You should be able to find all of the necessary techniques in the Java
Tutorial in the section about text areas or the section on caret listeners.
|
| |
|
| |
 |
Knute Johnson

|
Posted: 2006-3-24 13:39:00 |
Top |
java-programmer >> JTextArea size limitiing question ...
Charles Morison wrote:
> I'm using a JTextArea within a JScrollPane within a JViewPort. I am
> using the JTextArea to mimic a HyperTerminal like terminal emulation
> interface. When I set up the JTextArea I specify the viewable rows and
> columns, but since it is inside the JScrollPane it obviously can grow
> "infinitely" large (and eventually throw a heap memory exception). My
> desire is to not allow this, but was hoping that there was something
> within Java itself to passively limit the size of the JTextArea.
>
> Currently I use it to receive diagnostics (through a serial
> communications port) from an embedded device, so during testing I could
> conceivably let this run for several days (which will most certainly
> induce a heap memory exception). I am also logging all of the
> diagnostics to a file so I have no need for the JTextArea to grow
> "infinitely" large.
>
> So is there a way to passively limit the ultimate size of a JTextArea
> that I am missing or do I have to actively determine its size and trim
> it down some how (and if so, any suggestion on how to delete "old" data
> in a JTextArea)?
>
> Thanks, in advance, for any help.
Some of the JTextArea constructors take a Document argument. Use the
Document class below to set the size limit on your JTextArea.
//
//
// LengthLimitedDocument
//
//
import javax.swing.text.*;
public class LengthLimitedDocument extends PlainDocument {
protected int limit;
public LengthLimitedDocument(int limit) {
this.limit = limit;
}
public void insertString(int offs, String str, AttributeSet a)
throws BadLocationException {
super.insertString(offs, str, a);
int length = getLength();
if (length > limit)
remove(0,limit/20); // remove 5% of document if over limit
}
}
--
Knute Johnson
email s/nospam/knute/
|
| |
|
| |
 |
IchBin

|
Posted: 2006-3-24 15:54:00 |
Top |
java-programmer >> JTextArea size limitiing question ...
Charles Morison wrote:
> I'm using a JTextArea within a JScrollPane within a JViewPort. I am
> using the JTextArea to mimic a HyperTerminal like terminal emulation
> interface. When I set up the JTextArea I specify the viewable rows and
> columns, but since it is inside the JScrollPane it obviously can grow
> "infinitely" large (and eventually throw a heap memory exception). My
> desire is to not allow this, but was hoping that there was something
> within Java itself to passively limit the size of the JTextArea.
>
> Currently I use it to receive diagnostics (through a serial
> communications port) from an embedded device, so during testing I could
> conceivably let this run for several days (which will most certainly
> induce a heap memory exception). I am also logging all of the
> diagnostics to a file so I have no need for the JTextArea to grow
> "infinitely" large.
>
> So is there a way to passively limit the ultimate size of a JTextArea
> that I am missing or do I have to actively determine its size and trim
> it down some how (and if so, any suggestion on how to delete "old" data
> in a JTextArea)?
>
> Thanks, in advance, for any help.
I would do what the IBM's mainframe VM operating system did, and
probably still does, for CP and CMS internal trace tables. Just round
robin them. That is, after n-number, you define, just start to overwrite
it again from row 0. This would assumes that you had a time stamp on the
row for later review.
--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
|
| |
|
| |
 |
Charles Morison

|
Posted: 2006-3-25 12:44:00 |
Top |
java-programmer >> JTextArea size limitiing question ...
I already have a document class for the text area since I am analyzing
characters typed/entered while the text area is in focus before they are
sent to the serial port and determining whether characters received from
the serial port should be shown in the text area or whether they are
part of an escape sequence (since I'm emulating a terminal). So this is
probably the best approach. Didn't really notice that the Document
class provided a size limit.
Thanks for the tip.
Knute Johnson wrote:
> Charles Morison wrote:
>> I'm using a JTextArea within a JScrollPane within a JViewPort. I am
>> using the JTextArea to mimic a HyperTerminal like terminal emulation
>> interface. When I set up the JTextArea I specify the viewable rows
>> and columns, but since it is inside the JScrollPane it obviously can
>> grow "infinitely" large (and eventually throw a heap memory
>> exception). My desire is to not allow this, but was hoping that there
>> was something within Java itself to passively limit the size of the
>> JTextArea.
>>
>> Currently I use it to receive diagnostics (through a serial
>> communications port) from an embedded device, so during testing I
>> could conceivably let this run for several days (which will most
>> certainly induce a heap memory exception). I am also logging all of
>> the diagnostics to a file so I have no need for the JTextArea to grow
>> "infinitely" large.
>>
>> So is there a way to passively limit the ultimate size of a JTextArea
>> that I am missing or do I have to actively determine its size and trim
>> it down some how (and if so, any suggestion on how to delete "old"
>> data in a JTextArea)?
>>
>> Thanks, in advance, for any help.
>
> Some of the JTextArea constructors take a Document argument. Use the
> Document class below to set the size limit on your JTextArea.
>
> //
> //
> // LengthLimitedDocument
> //
> //
>
> import javax.swing.text.*;
>
> public class LengthLimitedDocument extends PlainDocument {
> protected int limit;
>
> public LengthLimitedDocument(int limit) {
> this.limit = limit;
> }
>
> public void insertString(int offs, String str, AttributeSet a)
> throws BadLocationException {
> super.insertString(offs, str, a);
> int length = getLength();
> if (length > limit)
> remove(0,limit/20); // remove 5% of document if over limit
> }
> }
>
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- 2
- Weird Static IssuePlease take a look at the following code section. In this module the
static "qt" becomes null when the constuctor is fired, very similar
code works find in other places in my program. I don't think the
QueryTools class is a problem because I can use the code elsewhere.
public class Authorization
{
static public String TABLE ="authorization";
static private String POOL_NAME = "mysql-invoice-system";
static private QueryTools qt;
static
{
System.out.println("Static Section " + POOL_NAME);
QueryTools qt = new QueryTools(POOL_NAME);
System.out.println(qt);
System.out.println("Static Section End " + POOL_NAME);
}
public Authorization()
{
System.out.println("Authorization Constructor");
System.out.println("QT=" + qt);
}
Here is the output from Netbeans:
run:
Static Section mysql-invoice-system
com.ciorent.HFCConnectionPool.QueryTools@18e2b22
Static Section End mysql-invoice-system
Authorization Constructor
QT=null
Here is the calling code:
Authorization a = new Authorization();
try
{
a.createAccount("email***@***.com", "test4200", 10000);
}
catch (Exception e)
{
System.out.println(e);
}
System.exit(1);
I am going to bet this is something simple that I am missing, hopefully
someone will be able to point out my error.
Thanks
HFC
- 3
- .ear files in Sun Java StudioHi all,
I am not sure if this is the right newsgroup for this question. But I just
thought that some of you may be able to help me out; that's why I am asking
you all this question.
I have a .ear file and I just downloaded Sun Java Studio Enterprise 8. May
I ask how can I import this .ear file in Sun Java Studio Enterprise 8? Can
someone point me to the right direction?
Thanks in advance,
Monte
--
---------------------------------------------
"Whatever my lot, thou has taught me to say, 'it is well; it is well with my
soul.'" -- Lyrics of It is well, it is well with my soul.
- 4
- prohibited methodwhat does it mean when we say ,
in EJB session bean
"The bean instance calls a prohibited method of its session context."
what does it mean by prohibited method ? who prohibits ? how can we
set this prohibition ?
thanks
- 5
- Get IP tomcat serverHi !
I am using Tomcat and i would like to get the host IP from the
servletContext object. Does anybody know how to get it ?
Thank you for your help
Best regards
Sylvain Caillet
- 6
- Efficient polling of a flatfileJust looking for feedback on what you might consider the most efficient
means to poll a flat file.
I need to have my app look at a flat file, say, every second or so, and read
any data that may have been appended to it.
Wondering what others might consider an efficient means of doing this in
Java. Would it be wise to merely look at the file size everysecond or so,
and, if that has changed, to then read it, starting from that byte which was
the previous size of the file on the previous polling a second ago?
Is there a more efficent way to do this? Thanks, Ike
- 7
- Can't read JAAS config from JARWe have an application that uses JAAS for security.
Until now the JAAS config file was in a folder (conf/) and the
application just ran fine.
To prepare for the deployment of the application with Webstart I packed
the folder with the config file in the application's JAR. Now JAAS
can't seem to find the file anymore.
Working:
|--application.jar
|--conf/
|--auth.conf
Failing:
|--application.jar
|--conf/
|--auth.conf
Both have the same manifest:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)
Main-Class: com.fpc.nokeos.core.client.launch.Launcher
Class-Path: . conf
I also tried expliciitely adding "conf/auth.conf" to manifest but it
didn't work either.
The stacktrace I get is
08:57:42,250 - ERROR: [NokeosClientSecurity] Could not connect to the
server.
Please check your network connection.
java.lang.SecurityException: conf/auth.conf (No such file or directory)
at
com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java:97)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at
java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at java.lang.Class.newInstance0(Class.java:350)
at java.lang.Class.newInstance(Class.java:303)
at
javax.security.auth.login.Configuration$3.run(Configuration.java:216)
at java.security.AccessController.doPrivileged(Native Method)
at
javax.security.auth.login.Configuration.getConfiguration(Configuration.java:210)
at
javax.security.auth.login.LoginContext$1.run(LoginContext.java:237)
at java.security.AccessController.doPrivileged(Native Method)
at
javax.security.auth.login.LoginContext.init(LoginContext.java:234)
at
javax.security.auth.login.LoginContext.<init>(LoginContext.java:403)
at
com.fpc.nokeos.core.client.security.NokeosClientSecurity.login(NokeosClientSecurity.java:46)
at
com.fpc.nokeos.core.client.launch.Launcher.checkLogin(Launcher.java:89)
at
com.fpc.nokeos.core.client.launch.Launcher.main(Launcher.java:66)
Caused by: java.io.IOException: conf/auth.conf (No such file or
directory)
at
com.sun.security.auth.login.ConfigFile.init(ConfigFile.java:157)
at
com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java:95)
... 16 more
How can I make it work?
- 8
- Jmatlink help pleasei can use jmatlink to open matlab but I can't
get it to open an m files and therefore run a functions using thev
arrays. How do I get
it to open a certain m file, I have tried to set the path in matlab
but that doesn't work.
Please help.
--
Message posted via http://www.javakb.com
- 9
- JDBC Thin driver for Oracle doesnt loadI'm using Oracle's JDeveloper 10g so the driver should exist. however this
code raises the ClassNotFoundException. so my questions
1. Whats the simplest way to tell if the thin driver for oracle ( or any
other JDBC driver ) exists?
2. If it does not exist where can I download it and where should I put it?
3. If it exists then why doesn't this code run? I've even tried to register
with the DriverManager but the same error.
thx.
import java.sql.*;
public class JDBCThin
{
public static void main(String[] args)
{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch ( ClassNotFoundException e )
{
System.out.println(e.getMessage()) ;
}
}
}
- 10
- Designation standard output as File type I have a method (fragment below) that takes a File type "outFile"
as the output file. However, if the user of this method specifies
"null" for that parameter, I want to make the output go to standard
output instead of a file.
My question: To what do I set outFile (File type) to make the
output go to standard output (display)? System.out is of a type
PrintStream.
Thanks, Alan
public static void printData(File dir, File outFile)
{
try
{
if (outFile == null)
{
outFile = ?????; // Default is standard output (System.out)
}
. . .
- 11
- Freelance programmer / developerHello,
I am software developer looking for freelance or Full Time work, do you
have any work that need to done.. buzz me at johnleox @ gmail.com
my skill sets:
VB,
ASP (VBScript & Javascript),
SQL Server,
Access (VBA),
Excel (VBA),
.NET(ASP.NET / C#)
Oracle &
Crystal Reports
I can work on migration projects, supporting exsisting project and
looking out for new project.
If location or place of work is not important for you then buzz..
waiting for your work.
johnleox @ gmail.com
- 12
- Also, about JColorChooserIs it possible to edit which colors are available in a JColorChooser or
is it simpler to build my own popup window with color selections?
- 13
- 14
- setFont() on solarisHi,
In one of my methods, I have a call like:
label.setFont(new Font("Arial", Font.PLAIN, 9));
This call works fine on windows but not on solaris. Moreover, the
label's text gets truncated when it shows up ("Applications" shows as
"Applicati") I iterated through the fonts via
GraphicsEnvironment.getAllFonts() and Arial seems to be available to
the java graphics environment on solaris.
How do I get arial font on solaris and not cause the truncation? Any
suggestions?
Thanks.
- 15
- newbie Threads and JDialog Hello all
I've been working with Java for one year and I'm a newbie with
threads, I have the following problem which I suppose you experts can
help:
I have a JDialog extension which I create some JTabbedPane with
some tables. This JDialog and these tables, send data to other class
which performs some calculation. Now I have a problem and I suspect
that its related with threads.
The button actionPerformed listener call a JDialog method that send
data and also "tells" the table to send its data to the calculation
class. After the table send the data, the constructor of the external
calculation programm fails. I'm listing in a reduced way my code:
In the Main (just the part related with the JDialog)
// in the declaratins:
public InputsIntegrationDialog inputIntDiag;
.
.
.
if (operationIndex == INTEGRATION){
if(inputIntDiag == null){
inputIntDiag = new InputsIntegrationDialog(this, getGraph());
}
else
inputIntDiag.setVisible(true);
The InputsIntegrationDialog class resumed:
public class InputsIntegrationDialog extends JDialog implements
ActionListener{
public InputsIntegrationDialog(Window owner, VRGraph grap1) {
super();
this.tabbedPane = new JTabbedPane();
fixedCostsTable = new IntegrationTable();
variableCostsTable = new IntegrationTable();
variableCosts = makeTextPanel(res.getString("variableCosts"));
tabbedPane.addTab("variableCosts",variableCostsTable );
Box okCancel = Box.createHorizontalBox();
ok = new JButton(res.getString("Ok"));
ok.addActionListener(this);
runBut = new JButton(res.getString("Run"));
runBut.addActionListener(this);
. ..// box layouts etc...
Container contentPane = getContentPane();
contentPane.add(tabbedPane, BorderLayout.CENTER);
contentPane.add(vertBox, BorderLayout.PAGE_END);
this.pack();
this.setVisible(true);
}
public void runOPT(){
// initialize the calculation class (hiden)
//send the data from the tables to the calculation
variableCostsTable.sendDataToOpt(data 1, data 2);
// in the line bellow the problem happens!!!!!!!!!!
solver1.setNLP(nlp1.getNLP());
}
public void actionPerformed(ActionEvent e){
System.out.println("Action: " + e.getActionCommand().toString() );
if(e.getActionCommand().toString() == "Ok"){
this.setVisible(false);
}
else if(e.getActionCommand().toString() == "Run"){
// This Line calls runOpt() and inside runOPt the crashes happen
int res = this.runOpt();
if( res1 >= 0){
JOptionPane.showMessageDialog(this,
"Optimization sucessful","Message");
}
else
JOptionPane.showMessageDialog(this,
"Optimization NOT sucessful","Error");
this.setVisible(false);
}
}
}
|
|
|