| Java GUI lag during window resizing on laptop |
|
 |
Index ‹ java-programmer
|
- Previous
- 2
- crash during file writing, how to recover ?Hi
I'm writing a commercial program which must be reliable. It has to do
some basic reading and writing to and from files on the hard disk,
and also to a floppy.
I have foreseen a potential problem. The program may crash
unexpectedly while writing to the file. If so, my program should
detect this during startup, and then (during startup) probably delete the
data added to the file and redo the writing operation.
Are file writing operations atomic ? ie when you write to a file,
will it either do it succesfully, OR say half fail (eg write a few letters
and not finish), OR not commit any changes to the file if a crash at
this point occurs?
My next question is how is this handled in commercial programming? I
plan on writing a flag (say, a simple char) to another file (this
would signal that a file write is about to begin), and then
removing this char after the file writing operation is completed.
Then on startup i just check the flags. if flag hasn't been removed a
crash occurred, so have to open file and get rid of any garbage.
Has anyone done anything similar b4? if so how did you handle this
crash scenario. My application could totally stuff up if i don't
handle this right.
by the way, i'm using the java language and api. this might effect
how files are written to, so i thought i should mention this.
MANY THANKS
Joseph
- 2
- comp.lang.java.{help,programmer} - what they're for (mini-FAQ 2004-10-08)Last-Modified: Fri Oct 8 11:38:42 2004 by David Alex Lamb
Archive-name: computer-lang/java/help/minifaq
Posting-Frequency: every 4 days
Before posting read Jon Skeet's "How to get answers on the comp.lang.java.*
newsgroups" at http://www.pobox.com/~skeet/java/newsgroups.html
Java FAQs and advice:
- Java FAQ (Andrew Thompson) http://www.physci.org/codes/javafaq.jsp
including his list of other FAQs http://www.physci.org/codes/javafaq.jsp#faq
- Java/Javascript/Powerbuilder HOWTO (Real Gagnon)
http://www.rgagnon.com/howto.html
- Java Glossary (Roedy Green) http://www.mindprod.com/jgloss.html
- jGuru jFAQs (John Zukowski) http://www.jguru.com/jguru/faq/
- Focus on Java (John Zukowski) http://java.about.com/
- Java Q&A (David Reilly) http://www.davidreilly.com/jcb/faq/
- Java GUI FAQ (Thomas Weidenfeller) http://www.physci.org/guifaq.jsp
comp.lang.java.help Set-up problems, catch-all first aid.
According to its charter, this unmoderated group is for immediate help
on any Java problem, especially when the source of the difficulty is
hard to pin down in terms of topics treated on other groups.
This is the appropriate group for end-users, programmers and
administrators who are having difficulty installing a system capable of
running Java applets or programs. It is also the right group for
people trying to check their understanding of something in the
language, or to troubleshoot something simple.
comp.lang.java.programmer Programming in the Java language.
An unmoderated group for discussion of Java as a programming language.
Specific example topics may include:
o types, classes, interfaces, and other language concepts
o the syntax and grammar of Java
o threaded programming in Java - sychronisation, monitors, etc.
o possible language extensions (as opposed to API extensions).
The original charter said that discussion explicitly should not include
API features that are not built into the Java language and gave examples
like networking and the AWT. These days AWT belongs in clj.gui, and
networking (and many other APIs) are often discussed in clj.programmer.
Do not post binary classfiles or long source listings on any of these
groups. Instead, the post should reference a WWW or FTP site (short source
snippets to demonstrate a particular point or problem are fine). For some
problems you might consider posting a SSCCE (Short, Self Contained, Correct
(Compilable), Example); see http://www.physci.org/codes/sscce.jsp
Don't post on topics that have their own groups, such as:
comp.lang.java.3d The Java 3D API
comp.lang.java.advocacy Arguments about X versus Y, for various Java X and Y
comp.lang.java.beans JavaBeans and similar component frameworks
comp.lang.java.corba Common Object Request Broker Architecture and Java
comp.lang.java.databases Using databases from Java
comp.lang.java.gui Java graphical user interface design and construction
comp.lang.java.machine Java virtual machines, like JVM and KVM
comp.lang.java.security Using Java securely
comp.lang.java.softwaretools Tools for developing/maintaining Java programs
Don't cross-post between these groups and c.l.j.programmer or .help -- it just
wastes the time of people reading the general groups.
Don't post about JavaScript; it's a different language. See
comp.lang.javascript instead.
--
"Yo' ideas need to be thinked befo' they are say'd" - Ian Lamb, age 3.5
http://www.cs.queensu.ca/~dalamb/ qucis->cs to reply (it's a long story...)
- 2
- Modify image and save to fileI want to read a .png image from a file, replace a color with a new color,
and write it back to a .png file.
I've managed to read the file into a BufferedImage. I've got a PixelGrabber
to look at the pixels, identify those of the old color, and replace them
with the new color, leaving me with an int[] of the pixels I want.
How do I modify write the modified pixels out to a .png file? I don't care
if I overwrite the original image or write to a new one.
No matter how I try to do it I end up with a new file that is identical to
the original, even though I can tell my code is correctly identifying the
pixels I want to change.
Please help,
Tim
- 3
- Java ArchitectDoes this forum have an experienced Java Architect? I would like to
bounce a few questions to someone with some industry experience. I am
the project manager for a new software app. I would like some advice on
java architecture and technologies. Appreciate this is all high-level,
but if certain technologies jump out to you then please let me know.
Scenario: Message brokering of news items over a LAN
User view is a java applet or could be java enabled web page (some kind
of smart console running on their PC desktop)
For now the application will have 50 users all on the same internal
network.
Central Oracle/SQL Server Repository - holding messages.
All clients communicate with central database that holds messages and
configuration information.
Based on the config. found each java client will dynamically build drag
and drop lists/trees of this information.
Ability to screen capture based on a user selection and upload the
image to a DB repository
Each client will be able to post new messages to the server which will
need to alert the other clients.
An author of a message can see if messages have been read by the
consumers. If the user has not read the author can send a warning to
that particular user.
Licensing needs to be built in to restrict to 50 concurrent users.
Security login screens are required. Use central db server to
authenticate.
Scenario2: This is where it gets interesting. How would this change in
a WAN scenario? - Could this even work using zero front print java?
Also if you live in/near London then please let me know.
Andy
- 5
- Interfaces vs. Abstract.Greetings,
I have googled around a bit about this one and consulted my various Java
tomes on the differences between abstract classes and interfaces.
They seem to be similar ideas *_BUT_* interfaces have no method code (i.e.
only abstract methods), just signatures and final static identifiers.
Abstract classes can have method code as well a abstract methods, constants
and non-constants.
It is possible for a class to implement multiple interfaces (in C++ talk
inherit from multiple abstract base classes) but a class can only extend
one other class (again in C++ese inherit from one class).
Is this understanding correct?
What general guidelines do you use to determine when to use an interface vs.
abstract classes?
For example I am working on creating a ReportWriter. I want the ReportWriter
to be able to write out in PostScript, text, and in HTML. I am thinking
about using an interface.
All three need to create headers, footers, and write detail lines. However,
the details of each operation are completely different from the other.
Thanks
--
From: Mark A Framness <email***@***.com>
http: http://netnet.net/~farmer/index.html
With all of thy getting, get understanding!
Proverbs 4:7
- 6
- load JNI from resource file?I am able to write a C native interface and load it using the
System.loadLibrary() routine.
Is there anyway to store the native interface library (say
"hello.dll") into a jar and then load the file from the jar?
- 6
- Data entry applicationHi,
I am an intermediate computer science student and I am in need of a "macro
type" tool/language that will let me automate a data entry process. The
data entry is rather simple but requires connecting to a server in between
data inputs, which ends up taking a lot of time per entry (about 10 minutes
per complete entry). On average, there are 50 - 100 entries to be made (10
min * 50 entries = one hell of a boring day.) The data that is to be
entered is in Excel, and then I (or some other unlucky person) must enter
the data manually into a prompt/DOS-like program run in the Windows (2000)
environment.
Would you know of anything that could help? Is there a way to do something
like this with any language? What would be required to setup the automation
(in the Windows environment)? I am pondering if a simple Windows
application that replicates key-strokes and has a timer capability would do
the trick (although I doubt it would be able to read the spreadsheets)?
Please let me know if you have any suggestions or comments. My thanks in
advance for any help.
email***@***.com
- 6
- Brand Watches Fila Men's Matrice watch #FLA55302 Discount, Replica, FakeBrand Watches Fila Men's Matrice watch #FLA55302 Discount, Replica,
Fake
Browse our Fila Men's Matrice watch #FLA55302 replica watches, which
is sure the watch you are looking for at low price. There are more
high quality designer watch replicas for selection
Fila Men's Matrice watch #FLA55302 Link : http://www.watches-brand.com/Replica-Fila-8343.html
Brand : Fila ( http://www.watches-brand.com/Fila-Replica.html )
Model : Fila Men's Matrice watch #FLA55302
Description :
<p>Digital quartz movement, Sport watch, Regular timekeeping, 100 laps
memory, World time function, 8 schedules reminder, Chronograph 1/100,
Second - Alarm, Black polycarbonate case, Lime green polyurethane
selector buttons, Black polycarbonate case, Stainless steel caseback,
50 meters/165 feet water resistant</p>
Sale Price : $ 210.00
Fila Men's Matrice watch #FLA55302 Details :
<ul>
<li>Brand: Fila</li>
<li>Dial color: Black polycarbonate case, Digital dial (253 dot m</li>
</ul>
Fila Men's Matrice watch #FLA55302 is new brand replica, join
thousands of satisfied customers and buy your Fila with total
satisfaction. A watches-brand.COM 30 Day Money Back Guarantee is
included with every Fila Replica Series for secure, risk-free online
shopping. watches-brand.COM does not charge sales tax for the Fake
Fila Men's Matrice watch #FLA55302.
All of our replica watches are shipped via EMS to worldwide. Normally
it takes 3days to prepare the fake watch you ordered and 5-10days to
transmit depending on the different destination.We pay for the free
shipping cost for total quantity over 20 pcs. The EMS tracking NO.
will be sent by email when an order is shipped from our warehouse. No
more other charges from watches-brand.com such as the tax. If you have
any other questions please check our other pages or feel free to email
us by email***@***.com.
The Same Replica Fila Watches Series :
Fila Men's Metropolis watch #21204 :
http://www.watches-brand.com/Replica-Fila-8344.html
Fila Women's Metropolis watch #21206 :
http://www.watches-brand.com/Replica-Fila-8345.html
Fila Men's Polaris watch #FLA63273 :
http://www.watches-brand.com/Replica-Fila-8346.html
Fila Men's Polaris watch #FLA63298 :
http://www.watches-brand.com/Replica-Fila-8347.html
Fila Women's Posh watch #31407 :
http://www.watches-brand.com/Replica-Fila-8348.html
Fila Men's Proteon watch #21803 :
http://www.watches-brand.com/Replica-Fila-8349.html
Fila Men's Proteon watch #21813 :
http://www.watches-brand.com/Replica-Fila-8350.html
Fila Men's Synthesis watch #31304 :
http://www.watches-brand.com/Replica-Fila-8351.html
Fila Men's Synthesis watch #31308 :
http://www.watches-brand.com/Replica-Fila-8352.html
Fila Women's The Bits watch #21601 :
http://www.watches-brand.com/Replica-Fila-8353.html
Brand Watches Fila Men's Matrice watch #FLA55302 Discount, Replica,
Fake
- 7
- question about DES APIHello All,
The following is the code I wrote to do DES encryption.
public byte[] run ()throws Exception
{
// TODO Auto-generated method stub
byte[] re = null;
byte[]re1 = null;
if (key.length != 8){
throw new DesException("Invalid Key!!!");
}
KeyGenerator kg = KeyGenerator.getInstance("DES");
SecretKey sk = kg.generateKey();
SecretKeySpec desKey = new SecretKeySpec(key, "DES");
Cipher des = Cipher.getInstance("DES");
if ((comm == Cipher.DECRYPT_MODE) && (data.length != 8)){
throw new DesException("Invalid Key!!!");
}
des.init(Cipher.ENCRYPT_MODE, desKey);
int l = des.getOutputSize(8);
re = des.doFinal(data);
des.init(Cipher.DECRYPT_MODE, desKey);
l = des.getOutputSize(16);
re1 = des.doFinal(re);
return re;
}
I don't understand why I try entrypt 8 bytes data, the the length of
return value is 16 bytes, the first 8 bytes are what I want, what are
last 8 bytes? as far as I know, for des, the input block is 8 bytes,
output block is 8 bytes too. I use this return value to decrypt, I got
correct value.
If I just input first 8bytes to decrypt I got exception.
Anyone can explain this to me or recommend any detail document about
these API?
Thanks a lot.
- 7
- Execute JSP within a servlet ?Hi folks,
A bug in cocoon prevents me from using it with JSP ... so I decided to
do my own implementation. I want to load up and execute a JSP file from
within a servlet, and from the generated XML doc apply an XSL style
sheet, then send back HTML to the browser. This is doable right ? since
a jsp doc somehow gets compiled and executed within a servlet anyway
... Is there an example of how this can be done ?
Also, am I going to miss out on some possible caching that happens
magically when I invoke a jsp directly from the browser ?
Many thanks,
galpi
- 7
- Screen Fonts in SwingHello everybody;
Is there a way to access screen fonts (Fixedsys, Courier, Terminal ...)
on a windows machine using java swing. I tried the following. . .
GriphicsEnvironment.getAvailableFontFamilyNames()
but it does not return screen font names. I also tried
Font fn=new Font("Courier",Font.PLAIN,10)
But it returns 'Courier New' font instead of 'Courier'.
- 7
- Just upgraded to the newest jdk 1.5I just upgraded my jdk 1.5 to the newest version in ports after I saw a
commit fixing a performance issue.
My swing application now behaves very well without being sluggish at all
and looks much nicer than with jdk 1.4.
Thank you very much for your great work on this.
--
Christian Laursen
- 12
- Set Txd always UPHello,
I use Java Comm, and i would like to know if i can use Txd (or td)
like RTS or DTR with Java Comm and how could I do this?
sample setTxd( true) and Txd=12v
setTxd( false) and Txd=-12v
- 13
- native jdk release schedule questionHi folks,
I am trying to find any information regarding the release schedules of
native java1.4 in binary form. As far as I understand the license allows for
a binary distribution. On the freebsd site latest news regarding java is
from December 2003. How do things look like? Or my question makes no sense
at all?
Cheers, Dani
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 14
- why not Java?
The company I am working for hired a guy three months ago which is a strong M$
fan, and I am a Java fan and also a SCJP, but somehow he and my ex-boss deceide
we should have a standard language for future projects (we are using VB6
currently), so he said we all should using VB.Net/ASP.Net now, and he said I
should forget what I know about Java/JSP. When I said "Since VB.Net/ASP.Net are
both new to us, why cannot we give Java a chance?", but he said ".Net is the
future." and from his eyes, he seems want to say "you are fired if you do not
want move to .Net."
Should I find a new Java job?
|
| Author |
Message |
M. P.

|
Posted: 2006-3-10 19:49:00 |
Top |
java-programmer, Java GUI lag during window resizing on laptop
I was messing around with a Java application I developed on my latop
and noticed something interesting. There seems to be lag with resizing
the windows and resizing the panels via the dividers. BUT this lag
only occurs when my laptop runs on the battery, or, rather, you don't
see this when it is connected to an AC power source.
This also occurs in some other Java applications I downloaded and
tested. But there are others that do not have this behavior.
I am not sure why this happens. But what I do know is that some laptop
manufacturers reduce power consumption by limiting hardware (and
software) factors, including slowing the CPU clock -- not sure if that
is the cause.
Not sure if anyone can give any input to what might be causing this --
an is there a way to rewrite/manupilate my code so that it does not
happen?
|
| |
|
| |
 |
VisionSet

|
Posted: 2006-3-11 3:01:00 |
Top |
java-programmer >> Java GUI lag during window resizing on laptop
"M. P." <email***@***.com> wrote in message
news:email***@***.com...
> I am not sure why this happens. But what I do know is that some laptop
> manufacturers reduce power consumption by limiting hardware (and
> software) factors, including slowing the CPU clock -- not sure if that
> is the cause.
Probably, Swing speed is noticibly slower below about 700mhz cpu
I've been on that divide for 5 years!
>
> Not sure if anyone can give any input to what might be causing this --
> an is there a way to rewrite/manupilate my code so that it does not
> happen?
>
Don't use Swing frame decorations
More drastically use AWT
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Java / JSP hostingHi!
Im trying to find a good (and low budget) host for my website that runs
JSP and java servlets, that interact with paypal. They also use JCE
and Javamail.
Im currently hosted with godaddy, but I think I need to jump away from
them because they dont allow me to interact with paypal from a java
servlet.
I was wondering if anyone has had any good experiences with ANY hosting
company for these issues, specifically
http://www.adsinmedia.com/JSP-Servelets-Hosting-India.html
http://www.visionwebhosting.net/
http://www.belahost.com/pp/index.php
thanks for any feedback!
- 2
- why is remove(myPanel2) not working?Hello,
For some reason the
contentArea.remove(myPanel3);
works but the
contentArea.remove(myPanel2);
does not - any ideas please?
(happy to post the whole code if this helps)
Cheers
Geoff
if (textIndex == 0)
{
contentArea.remove(myPanel2);
contentArea.remove(myPanel3);
myPanel3 = new JPanel();
myPanel3.setBackground(Color.white);
JLabel endMessage = new JLabel("Thank you - all questions
answered");
myPanel3.add(endMessage);
contentArea.add(myPanel3, BorderLayout.SOUTH);
setContentPane(contentArea);
contentArea.setVisible(true);
}
- 3
- ClassCastException in ColorModel.getAlphaSometimes I get this exception. Anyone know why? Thanks!
Uncaught error fetching image:
java.lang.ClassCastException: java.lang.Object
at java.awt.image.ColorModel.getAlpha(ColorModel.java:854)
at java.awt.image.ColorModel.getRGB(ColorModel.java:899)
at
sun.awt.image.ImageRepresentation.convertToRGB(ImageRepresentation.java(Comp
iled
Code))
at
sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java(Compile
d
Code))
at
java.awt.image.AreaAveragingScaleFilter.accumPixels(AreaAveragingScaleFilter
.jav
a(Compiled Code))
at
java.awt.image.AreaAveragingScaleFilter.setPixels(AreaAveragingScaleFilter.j
ava:
241)
at sun.awt.image.PixelStore8.replayLines(PixelStore8.java:68)
at sun.awt.image.PixelStore.replay(PixelStore.java(Compiled Code))
at sun.awt.image.PixelStore.replay(PixelStore.java:176)
at
sun.awt.image.InputStreamImageSource.updateFromStore(InputStreamImageSource.
java
:333)
at
sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:282
)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:204)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:172)
- 4
- executing a jsp from a java applicationI have a jsp that checks which clients that are connected. This works
well! When I from a browser loads the jsp page, information about how
many clients is connected is presented in the browser and also
appended to a logfile on the Windows 2003 server machine.
Now I want to write a Java application that is to always be running on
the server. In this Java application there is a timer that expires,
lets say every 10 minutes. When the timer expires a certain method
(lets call it timerEventHandler) in the java application executes.
Question:
How can timerEventHandler execute the jsp so that information about
connected clients is appended to the logfile at every 10 minute?
I would really like som code for this. I have searched the Internet
for a couple of days now. I tried using JEditorPane and construct a
minimal webbrowser that would load the jsp page, but after trying
several examples of java webbrowsers it seems that I am behind proxys,
firewalls, or whatever that makes it impossible for me to load a
webpage. I can however start IE and load the page. Does anyone have an
idea what can be done?
thanks
- 5
- passing -D argument with white spaces on UNIXHi,
I try to pass a value to overwrite a value defined in the property
file by using following command on unix:
java -DMYENV="my value here" javaClass...
java cannot interpret it correctly, how can I get around it?
Thanks
WM
- 6
- Memory utilizationI was trying to profile the following piece of code using NetBeans:
public static void main(String[] args)
{
Map<String, String> map = new HashMap<String, String>();
for( int i = 0; i < Integer.MAX_VALUE; ++i )
{
map.put(Integer.valueOf(i).toString(),
Integer.valueOf(i).toString());
}
}
I set my max and min heap size to be 1GB. I find that the program dies
after having created 4M entries (at which point the heap used is at
1GB) although the memory used by the objects as indicated by the
Netbeans memory profiler is the following:
String -- 48MB
char[] -- 48 MB
HeapCharBuffer -- 45MB
Integer -- 19MB
HashMap$Entry -- 19MB
This totals to less than 200 MB and the rest of the objects are at 0%
of the total used memory at most another 200MB. How come the heap
usage is at 1GB at this point of time? I am extremely confused. Could
someone please explain what might be going on?
Thanks
A
- 7
- I am a Java Virgin! I need your support.I do agree with both of you, I probably wasnt clear. I just meant I
found pascal good for teaching me the basics of programming (loops,
conditions, passing parameters etc) but yes OO is a lot different and
requires a different mind set when is comes to solving a problem. Also I
agree on using BlueJ to get into Java and the OO side of programming. I
used this when first learning and still do on some occassions as it is
very clear in laying out classes and how they relate to each other, also
it's good for inspecting the properties of a class while the code is
running.
Michael Redlich wrote:
> Daniel Dyer wrote:
>
>>I also went from Pascal (and BASIC before that) to Java. While Pascal may
>>be easier to pick-up, the problem with going from procedural to OO is that
>>you have to unlearn a lot of things because it is a different way of
>>thinking. The key to feeling comfortable in Java is having a good grasp
>>of objects. If you come from a procedural background you have
>>preconceptions about how to program that could be a hinderance in the OO
>>world. Ways of writing good code in Pascal are bad habits in Java.
>
>
> Dan:
>
> I, too, learned procedural programming before OOP. I remember learning
> FORTRAN IV on an IBM mainframe with keypunch cards. From there it was
> BASIC, Pascal, C, then finally C++ and Java.
>
> I understand and agree with what you said about switching from
> procedural to OOP. However, I also think that it made me appreciate
> OOP more.
>
> A few years ago, Bjarne Stroustrup was interviewed about which language
> would be better for a new programmer to learn - C or C++. I was a bit
> surprised that he recommended C++. I suppose that I was thinking about
> the learning curve for the STL, but then again, who says that a new
> programmer would necessarily have to use the STL right away?
>
> Since the OP was very new to any kind of programming, I recommended
> that he learn the basics of any programming language: loops,
> conditionals, etc., and learn how to avoid potential pitfalls such as
> inadvertantly writing infinite loops. I think that's more important
> regardless of which programming language he chooses.
>
> Sincerely,
>
> Mike.
>
> ------
> ACGNJ Java Users Group
> http://www.javasig.org/
>
- 8
- AWT/Swing layout behavior?I am having trouble figuring out the right way to use the GridBagLayout
class.
I have some sample code (see below) that I _expected_ would take the two
components added to the frame and always make them the same size, arranged
vertically.
What happens instead is that when one of the two components is a Panel or
JPanel (and possibly other container types...those are the two I tested),
if that component contains another component, it takes up more than half
of the frame.
Reading the documentation, I am under the impression that the
GridBagLayout class automatically allocates the dimensions of a given
component according to the weight assigned to it in the GridBagConstraints
class set for the component. Thus, since these two components have the
same weights, they should always be equally sized. But for some reason,
having the container actually contain something affects this.
The sample code only adds one item, and the difference in size is
noticeable but not very large. However, this came up in a more complex
situation, where a larger number of controls are added. In that case, the
size difference is proportionally larger as well, resulting in effective
relative weights more like 3 or 4 to 1.
Is there a way to get the GridBagLayout class, or some other built-in
LayoutManager, to do this sort of auto-sizing where the relative weights
will always actually stay equal?
Thanks!
Pete
p.s. Something I ran into while putting the sample code together is that
sometimes when I'd run the code, the button would not show up. It'd be
briefly visible, and it would show up again once the window is resized.
But to start with, it's not visible. Is there some basic flaw in the way
I'm creating this UI that is leading to this erratic behavior? Or am I
just looking at some sort of run-time bug?
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class TestPanel
{
/**
* @param args
*/
public static void main(String[] args)
{
Frame frame = new Frame("TestPanel");
GridBagLayout grid = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
JPanel panel;
frame.setLayout(grid);
constraints.fill = GridBagConstraints.BOTH;
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.weightx = 1;
constraints.weighty = 1;
panel = new JPanel();
panel.setBorder(new LineBorder(Color.BLACK));
panel.add(new Button("Test"));
frame.add(panel);
grid.setConstraints(panel, constraints);
panel = new JPanel();
panel.setBorder(new LineBorder(Color.BLACK));
frame.add(panel);
grid.setConstraints(panel, constraints);
frame.setSize(240, 480);
frame.setVisible(true);
}
}
- 9
- findind how many characters in some amount of pixels.Hi ,
I am working on JTable data printing.In that i have some problem.If
anyone can help me,please help me.
how to find the no.of characters in some amount of pixels ?
TableColumn tk = colModel.getColumn(nCol);
int width_1 = tk.getWidth();
finding string width using
fontMetric.stringWidth(string);
how to substring the string based on coloum width and string width
which will fit into the particular column.
If anybody knows solution for this problem, Please give me the reply.
thanking you
Bharath
- 10
- New Software Development Articles DirectoryA new links directory of articles related to software development is
"under construction" on http://www.softdevarticles.com/
Please feel free to use it in you next research and to contribute with
your articles on Java.
- 11
- Serialize Applet to a web server via Servlet ProblemHi,
I try to Serialise an Applet on my WebServer, i convert Object to
ByteArray, before sending it to webserver.
There is 2050 bytes in byte array on my applet before sending it, and
2062 bytes in byte array on tomcat !
Where is my mistake ?
Regards
Philippe
Applet
void WriteApplet(String filename)
{
ObjectOutputStream out;
System.out.println("Debut Test WRITE APPLET...");
//Serialisation de la frame
try
{
String m_URL=new
String("http://172.16.0.101:8080/test/servlet/servletgraph.XXServlet");
String string4=m_URL;
System.out.println("w01 "+string4);
URL u=new URL(string4);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(this);
oos.flush();
oos.close();
byte b[] = baos.toByteArray();
HttpURLConnection urlc = (java.net.HttpURLConnection)
u.openConnection();
// Set the Post (true) or Get (false) method.
urlc.setDoOutput(true);
urlc.setDoInput(true);
urlc.setUseCaches(false);
urlc.setAllowUserInteraction(false);
urlc.setRequestProperty("Content-Type",
"application/octet-stream");
String lengthString = String.valueOf(baos.size());
urlc.setRequestProperty("Content-Length", lengthString);
System.out.println("Object is avant ecriture " + lengthString + "
bytes");
out = new ObjectOutputStream(urlc.getOutputStream());
out.write(b);
if (urlc.getResponseCode() != HttpURLConnection.HTTP_OK) {
System.out.println("Error...");
} else {
System.out.println("I have now access to the stream...");
// blaha balaaha blaahahaha
}
out.flush();
out.close();
System.out.println("Fin Test WRITE APPLET...");
}
catch (IOException ioe) {
System.err.println(ioe);
ioe.printStackTrace();
}
}
-------------------------------------------------------------------------
Servlet
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
System.out.println("XXServlet doPost X1 "+new Date());
boolean debug=true;
InputStream in = req.getInputStream();
byte[] bufimage=null;
bufimage = new byte[4 * 1024]; // 4K buffer
int len;
RandomAccessFile f = new
java.io.RandomAccessFile(req.getRealPath("/")+"xxservlet", "rw");
int size = req.getIntHeader("content-length");
bufimage = new byte[size]; // 4K buffer
if(debug) System.out.println("XXServlet bytearray02 "+size);
int nb=0;
while ((len = in.read(bufimage, 0, bufimage.length)) != -1)
{
if(debug) System.out.println("XXServlet bytearray03
content-length "+len);
f.write(bufimage, 0, len); //Fichier
nb=+len;
}
if(debug) System.out.println("XXServlet bytearray05 "+nb);
f.close();
if(debug) System.out.println("XXServlet write04 ");
}
}
- 12
- UnixODBCconfig-root wont startI have UnixODBC installed on my Mandriva 2008, of late I cannot seem
to start ODBCconfig-root, when i run it via terminal i get the root
pass dialog but then it dies giving me this error...
ODBCConfig-root: symbol lookup error: ODBCConfig-root: undefined
symbol: ODBCINSTSQLManageDataSources
Can someone help me through this?
- 13
- No window control in an Application WindowHi,
After following a JFACE eclipse example, i created a new class that
extends ApplicationWindow that create a nice window with tool bar, menu
bar and status bar. That's great.... but my window doesn't have window
controls to minimize or iconify it, only the quit element (the cross)!
Does anybody know which attribute i have to set to have window
controls?
Thx
0o.
- 14
- How about to lauch a new thread in a constructor?I read one piece of code written by somebody and behold interesting
class as below:
class SomeFramework {
public SomeFramework() {
...
DameonThread dameon = new DameonThread();
dameon.start();
}
private doSomething() {
...
}
private class DameonThread extends Thread {
public void run() {
...
doSomething();
...
}
}
}
As you can see, in the constructor of SomeFramework, one thread is
launched and that thread will call the SomeFramework instance's private
method. Perhaps the author design this code to make the client code
easy. The client just call "new SomeFramework()" and everything is done.
No need to coding like
SomeFramwork framework = new SomeFramework();
framework.lauch();
However, the problem is that it is possible that when the dameon is
started, CPU will go into run and call doSomething() of the instance of
SomeFramework. But, at that time, the constructor is not returned. Is it
reasonable to call a method of a un-instanstized object? Curiously, this
code works well all the time. Luckily, before dameon is started, all
member variables are instantized in constructor, but I really think this
code is ugly and should be avoided.
- 15
- metadata and stored proceduresHi everybody,
I use a CallableStatement to run my stored procedure, and I would like
to retrive the columns name of the result.
So I try to use the getMetaData method of my CallableStatement, but it
returns me null futhermore than le callablestatement returns data.
How can I do to retrieve my columns names ?
Thanks
Thomas
|
|
|