 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Thu Jul 13, 2006 11:16 pm Post subject: Re: Auto Select text on textfield focus |
|
|
therodet (AT) gmail (DOT) com wrote:
| Quote: | I want to make JTextFields in my application automatically select all
text when they receive focus, whether by mouse or by keyboard. More
importantly, I don't want to have to manually install listeners on
every JTextField I create.
It seems to me that this should be doable with a modified Look And
Feel, but I know nothing about modifying a LaF. Ideally, I would like a
solution that would automatically work with any LaF, though this is
less important; if I have to customize a specific LaF of my choice and
stick with that, then it's not a problem.
I'd also like to hear of any other suggested methods for accomplishing
this feat.
Thanks in advance,
Eldon
|
FWIW, I found exactly what I was looking for ->
http://www.javalobby.org/java/forums/t17439.html |
|
| Back to top |
|
 |
mtp Guest
|
Posted: Mon Jul 17, 2006 2:09 pm Post subject: Re: Drawing 25 000 Shape fast |
|
|
Oliver Wong wrote:
| Quote: | [post re-ordered]
"MTP" <mtp (AT) nowhere (DOT) invalid> wrote in message
news:e95r4e$lkr$2 (AT) s1 (DOT) news.oleane.net...
Andrey Kuznetsov a écrit :
i have to render 25 000 "points" with each one a specific fill
color, and a specific Shape (java.awt.Shape or customized) in a JPanel.
Drawing every Shape, one by one, is too slow (panning the view ins't
smooth). So i tried to create a BufferedImage for each point, and
render them instead. But it is even slower.
Direct : 3 sec
BI: 4.5 sec
And all the BI take about 60 Mbytes of memory, which is a lot.
use one BufferedImage.
You need to draw your shapes to BI only if something changes.
I already use this. But it's unusable if one of these events happen:
- pan (let's say that i'm at Zoom Factor 2000)
Zoom factor 2000? So if an object was previous 1x1 pixel, it is now
2000x2000 pixels?
|
yes
| Quote: | - zoom
- resize
What's the difference between zoom and resize, assuming vector (i.e.
not raster) images?
|
weel zoom changes the data viewed, while resize change the way data are
viewed
| Quote: | - the user want to map column 3 instead of column 4 for colors OR size
of the shape OR type of shape
I need to reach 0.1 sec by any mean. Right now i'm thinking to add
some kind of Z-buffer but with aliasing it's pretty hard i think.
Trying ideas take time so i'm asking if somebody can help me.
Have you considered using Java3D/OpenGL and taking advantage of the
3D accelerator to perform zoom and pan?
|
i've tried -Dsun.java2d.opengl=true but the JVM was unstable and the
performance boost was small. |
|
| Back to top |
|
 |
mtp Guest
|
Posted: Mon Jul 17, 2006 2:16 pm Post subject: Re: Drawing 25 000 Shape fast |
|
|
Larry Barowski wrote:
| Quote: | "MTP" <mtp (AT) nowhere (DOT) invalid> wrote in message
news:e95r4e$lkr$2 (AT) s1 (DOT) news.oleane.net...
Andrey Kuznetsov a écrit :
use one BufferedImage.
You need to draw your shapes to BI only if something changes.
I already use this. But it's unusable if one of these events happen:
- pan (let's say that i'm at Zoom Factor 2000)
When panning, you just use copyArea() to move the part of the
image that will still be in view, and only redraw to the exposed
areas. So if the pan moves the image one pixel, you do one
copyArea(), then redraw to the one-pixel wide exposed area.
Assumning you have some sort of shape-level culling in place,
this should be quite fast.
|
1/ copyArea() : ok
2/ partial redrawing : the thing is that right now, i'm parsing every
data, and do some test on x and y for "custom made clipping". I would
ned to do it in a sorted way, because simple clipping will not boost
enough i think.
3/ shape-level culling?
| Quote: |
- zoom
- resize
While zooming, you may want to display a limited form of the
shapes. For example, you could show just the centerpoints, or an
outline - whatever is enough to give the user a sense of the zoom
level. Then when the zoom is finished, do a normal redraw.
You could also do this while panning. 3 seconds for a full redraw
may still be intolerable, but you can probably get away with a
half second or so, and the .1 second requirement can apply to
the centerpoint or outline drawing mode only.
|
weel i would like to avoid showing only centerpoints, only in last resort
| Quote: | For overall speed, if the shapes are simple enough, try rendering
yourself to an int array and using setRGB() to place the data in
the image. You could try it for rectangles and see what kind of
speed you get.
|
i will try, but i don't know how to implement a fast anti-aliasing
circle draw method |
|
| Back to top |
|
 |
mtp Guest
|
Posted: Mon Jul 17, 2006 2:17 pm Post subject: Re: Drawing 25 000 Shape fast |
|
|
Larry Barowski wrote:
| Quote: | I'm not sure why you bring up a Z-buffer for 2D shapes. Are
they sorted by depth? If so, how long does the sort take?
|
no they are not sorted, i just though about it when i saw so much shape
overlapping. |
|
| Back to top |
|
 |
Larry Barowski Guest
|
Posted: Mon Jul 17, 2006 9:29 pm Post subject: Re: Drawing 25 000 Shape fast |
|
|
"mtp" <mtp (AT) srs (DOT) invalid> wrote in message
news:e9fkgf$urs$1 (AT) s1 (DOT) news.oleane.net...
| Quote: | Larry Barowski wrote:
"MTP" <mtp (AT) nowhere (DOT) invalid> wrote in message
news:e95r4e$lkr$2 (AT) s1 (DOT) news.oleane.net...
When panning, you just use copyArea() to move the part of the
image that will still be in view, and only redraw to the exposed
areas. So if the pan moves the image one pixel, you do one
copyArea(), then redraw to the one-pixel wide exposed area.
Assumning you have some sort of shape-level culling in place,
this should be quite fast.
1/ copyArea() : ok
2/ partial redrawing : the thing is that right now, i'm parsing every
data, and do some test on x and y for "custom made clipping". I would ned
to do it in a sorted way, because simple clipping will not boost enough i
think.
3/ shape-level culling?
|
Shape-level culling is what you probably mean by
"custom made clipping". Culling means you throw out
shapes that will definitely not show up in the exposed
area. Clipping means you reduce the shape to the
portion that will appear in the exposed area. For culling
you want a quick test that may not cull in all situations
but gets most of them - typically you would use a
rectangular bounding box. For a circle you could do
x + r < minx || x - r > maxx || y + r < miny || y - r < maxy.
Time to cull 25,000 shapes in this way will be a small
fraction of your .1 second requirement.
| Quote: | While zooming, you may want to display a limited form of the
shapes. For example, you could show just the centerpoints, or an
outline - whatever is enough to give the user a sense of the zoom
level. Then when the zoom is finished, do a normal redraw.
You could also do this while panning. 3 seconds for a full redraw
may still be intolerable, but you can probably get away with a
half second or so, and the .1 second requirement can apply to
the centerpoint or outline drawing mode only.
weel i would like to avoid showing only centerpoints, only in last resort
|
Outlines may be fast enough, and give the user enough context
to judge how much they are zooming. In any case, you should
try turning off antialiasing during the zoom. You can always
make this a user-selectable setting, so those with fast machines
can zoom in normal mode if they wish.
| Quote: | For overall speed, if the shapes are simple enough, try rendering
yourself to an int array and using setRGB() to place the data in
the image. You could try it for rectangles and see what kind of
speed you get.
i will try, but i don't know how to implement a fast anti-aliasing circle
draw method
|
Will your shapes overlap? If not, check any computer graphics
textbooks you have access to for an antialiased circle rendering
algorithm. If they do overlap, oversampling will give you
antialiasing plus edge blending. Again, a graphics textbook will
give you the basics of that. It will slow down your rendering a lot
though. Four-times oversampling will give good results, but it
means rendering everything four times, plus some time needed
to accumulate the results. |
|
| Back to top |
|
 |
Oliver Wong Guest
|
Posted: Tue Jul 18, 2006 6:12 pm Post subject: Re: Drawing 25 000 Shape fast |
|
|
"mtp" <mtp (AT) srs (DOT) invalid> wrote in message
news:e9fk4d$udq$1 (AT) s1 (DOT) news.oleane.net...
| Quote: | Oliver Wong wrote:
[post re-ordered]
Zoom factor 2000? So if an object was previous 1x1 pixel, it is now
2000x2000 pixels?
yes
|
So if the user's screen resolution is 1600x1200, the one pixel would be
bigger than the entire screen, right? I assume you test whether objects are
on screen before you attempt to draw them, right? With a zoom factor of
2000, you'd probably only ever have to draw 1 object at a time, which should
be very fast.
| Quote: | What's the difference between zoom and resize, assuming vector (i.e.
not raster) images?
weel zoom changes the data viewed, while resize change the way data are
viewed
Have you considered using Java3D/OpenGL and taking advantage of the 3D
accelerator to perform zoom and pan?
i've tried -Dsun.java2d.opengl=true but the JVM was unstable and the
performance boost was small.
|
You'd have to rewrite code. I.e. create actual 3D objects which
coincidentally all have the same Z coordinate. Even very cheap (under $60)
videocards should have no problem rendering 25000 polygons.
- Oliver |
|
| Back to top |
|
 |
mtp Guest
|
Posted: Wed Jul 19, 2006 2:38 pm Post subject: Re: Drawing 25 000 Shape fast |
|
|
Oliver Wong wrote:
| Quote: |
"mtp" <mtp (AT) srs (DOT) invalid> wrote in message
news:e9fk4d$udq$1 (AT) s1 (DOT) news.oleane.net...
Oliver Wong wrote:
[post re-ordered]
Zoom factor 2000? So if an object was previous 1x1 pixel, it is
now 2000x2000 pixels?
yes
So if the user's screen resolution is 1600x1200, the one pixel would
be bigger than the entire screen, right? I assume you test whether
objects are on screen before you attempt to draw them, right? With a
zoom factor of 2000, you'd probably only ever have to draw 1 object at a
time, which should be very fast.
|
yes but it was to explain that i can't stock the full offscreen image
and show only a piece with a zoom factor equal to 2000.
| Quote: | What's the difference between zoom and resize, assuming vector
(i.e. not raster) images?
weel zoom changes the data viewed, while resize change the way data
are viewed
Have you considered using Java3D/OpenGL and taking advantage of
the 3D accelerator to perform zoom and pan?
i've tried -Dsun.java2d.opengl=true but the JVM was unstable and the
performance boost was small.
You'd have to rewrite code. I.e. create actual 3D objects which
coincidentally all have the same Z coordinate. Even very cheap (under
$60) videocards should have no problem rendering 25000 polygons.
|
Humm... i can't do that.
> - Oliver |
|
| Back to top |
|
 |
johnmmcparland Guest
|
Posted: Tue Aug 08, 2006 6:20 pm Post subject: Re: JTable column headers - how? |
|
|
Thanks Rogan and Dieter,
I had been adding my table to a JPanel, mid_pane, which was in a scroll
pane;
scroller= new JScrollPane(mid_pane).
I should have just added the table straight onto the scrollpane;
scroller= new JScrollPane(table);
I will take your advice into consideration Dieter as I think it will
help with my next problem, adding checkboxes into my table. If you
have any hints or examples, they would be most welcome..
thanks again,
John |
|
| Back to top |
|
 |
Rogan Dawes Guest
|
Posted: Tue Aug 08, 2006 7:05 pm Post subject: Re: JTable column headers - how? |
|
|
johnmmcparland wrote:
| Quote: | Thanks Rogan and Dieter,
I had been adding my table to a JPanel, mid_pane, which was in a scroll
pane;
scroller= new JScrollPane(mid_pane).
I should have just added the table straight onto the scrollpane;
scroller= new JScrollPane(table);
I will take your advice into consideration Dieter as I think it will
help with my next problem, adding checkboxes into my table. If you
have any hints or examples, they would be most welcome..
thanks again,
John
|
It is very easy to add checkboxes to a table, you simply need to report
the correct column class (i.e. Boolean.class) for the appropriate
column. The default TableCellRenderer and TableCellEditor will use a
JCheckbox for presenting and modifying table cell values, if it sees
that the column class is Boolean.
You most likely want to extend AbstractTableModel as explained by Dieter:
<http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/table/AbstractTableModel.html>
Apart from the required abstract methods, you would want to override
getColumnClass(int column):
public Class getColumnClass(int column) {
if (column == myBooleanColumnIndex) {
return Boolean.class;
}
return Object.class; // or whatever you like for the other columns
}
Hope this helps
Rogan |
|
| Back to top |
|
 |
johnmmcparland Guest
|
Posted: Tue Aug 08, 2006 8:12 pm Post subject: Re: JTable column headers - how? |
|
|
Rogan Dawes wrote:
| Quote: | johnmmcparland wrote:
Thanks Rogan and Dieter,
I had been adding my table to a JPanel, mid_pane, which was in a scroll
pane;
scroller= new JScrollPane(mid_pane).
I should have just added the table straight onto the scrollpane;
scroller= new JScrollPane(table);
I will take your advice into consideration Dieter as I think it will
help with my next problem, adding checkboxes into my table. If you
have any hints or examples, they would be most welcome..
thanks again,
John
It is very easy to add checkboxes to a table, you simply need to report
the correct column class (i.e. Boolean.class) for the appropriate
column. The default TableCellRenderer and TableCellEditor will use a
JCheckbox for presenting and modifying table cell values, if it sees
that the column class is Boolean.
You most likely want to extend AbstractTableModel as explained by Dieter:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/table/AbstractTableModel.html
Apart from the required abstract methods, you would want to override
getColumnClass(int column):
public Class getColumnClass(int column) {
if (column == myBooleanColumnIndex) {
return Boolean.class;
}
return Object.class; // or whatever you like for the other columns
}
Hope this helps
Rogan
|
Thanks that's what I did.
Might I ask - how would I listen for a single row being selected, the
ListSelectionEvent seems to be a bit too much as all I want to do it
listen for a single row being selected and handle that event. |
|
| Back to top |
|
 |
Daisy Guest
|
Posted: Fri Aug 11, 2006 4:43 pm Post subject: Re: setProperty("headless","true") weirdness? |
|
|
Thanks everyone who gave advice!
Here's the revised code which resolved the problem:
System.setProperty( "java.awt.headless" , "true" );
Toolkit tk = Toolkit.getDefaultToolkit( );
try {
// JFrame frame = new JFrame( );
// frame.getContentPane( ).add( c );
JPanel panel = new JPanel( );
panel.add( c );
panel.addNotify( );
In addition to setting the headless property, I had to swap from Frame
to Panel.
Thanks,
Jeff
Norman D. wrote:
| Quote: | Here is a link which might be helpful:
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/
--Norman
Daisy wrote:
Can anyone provide insight on System.setProperty( "java.awt.headless" ,
"true" )?
I've been struggling with a HeadlessException in the line:
JFrame frame = new JFrame( );
So I added System.setProperty( "java.awt.headless" , "true" ) before
the JFrame call. However, JFrame still throws this error. Shouldn't
setting the property inform the JVM that it is headless?
System.setProperty( "java.awt.headless" , "true" );
try {
JFrame frame = new JFrame( );
frame.getContentPane( ).add( c );
frame.addNotify( );
} catch ( HeadlessException e ) {
printStackTrace( );
}
It is a Redhat computer running Hotspot 1.5.0_07 and Tomcat 5.5.17. It
is headless. The application is a servlet that runs fine on linux
machines with monitors. I tried the -Djava.awt.headless=true argument
long ago and still use it.
I'd really appreciate any insight on this problem,
Thanks! |
|
|
| Back to top |
|
 |
Rogan Dawes Guest
|
Posted: Tue Aug 15, 2006 6:45 pm Post subject: Re: JTable column headers - how? |
|
|
johnmmcparland wrote:
| Quote: | Thanks that's what I did.
Might I ask - how would I listen for a single row being selected, the
ListSelectionEvent seems to be a bit too much as all I want to do it
listen for a single row being selected and handle that event.
|
ListSelectionEvent is can be a bit more complicated than you need. What
is sometimes easier is just to get the selected rows from the table when
you are told that a change has occurred.
in many cases, your method will look something like:
public void valueChanged(ListSelectionEvent evt) {
if (evt.getValueIsAdjusting()) return;
int[] selection = table.getSelectedRows();
if (selection.length == 0) {
// no rows selected
} else {
// selection has indices of selected rows
}
}
Rogan |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Mon Aug 28, 2006 6:15 pm Post subject: Re: how to import csv data to a jTable |
|
|
dsilvawilliam (AT) gmail (DOT) com wrote:
Please refrain from multi-posting.
(X-posted to c.l.j.h,p,g w/f-ups to c.l.j.h.)
Andrew T. |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Sun Sep 24, 2006 7:10 am Post subject: Re: JAVA TEXT AREA GUI problem |
|
|
KL wrote:
| Quote: | Is anybody know how ...
|
Possibly someone on any of the other messages
you have multi-posted*, knows..
(X-posted to c.l.j.p/g. with F-Ups to c.l.j.p. only)
* ..but no, probably not on the 'J2EE' google group!
Andrew T. |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Mon Oct 02, 2006 7:10 am Post subject: Re: Java Data Binding - Bad? |
|
|
Michael Rauscher wrote:
| Quote: | Andrew Thompson schrieb:
I have been wrestling with any number of GUI based
configuration matters recently (both configuring the GUI
itself, as well as objects loaded/created by the applications).
It seems to take in inordinate amount of Java code to
complete the 'simple matter'* of getting a random object's
values onscreen (usually with validating constraints added).
Is it just my imagination** or is Java an extraordinarily
poor language for data binding?
No.
IMO the problem isn't the Java language but missing support in the
Platform libraries.
|
Aha! So, I am expecting the data binding in the core API,
whereas you are suggesting it should be a framework on top?
| Quote: | There are several JSRs dealing with data binding/application frameworks
whereas I'd like to see an application framework.
|
Oh - right..
Thanks for the further info. ..I have been rather remiss
in *not* checking some of the frameworks you
mentioned, more closely. I was not aware of the JSR's.
Will look into those further.
Andrew T. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|