Home » Category » Java in Newer

Java in Newer: XYLayout / JTable

200| Tue, 29 Apr 2008 20:05:00 GMT| mark| Comments (6)
Hello,

I'm experiencing problems with a JTable & assorted layouts.

My Java application displays a number of records returned from a database in
a JTable, which is held in a JScrollPane. The scroll pane previously used an
XYLayout to display the JTable, and I used a method taken from
http://www.chka.de/swing/table/cell-sizes.html to make the table's columns
as wide as the widest item of data or column header.

I've subsequently experienced problems with the XYLayout (moving from 1.3 to
1.4) and, as such, need to change the layout for the scroll pane for
something else. I've tried to replace the scroll pane's XYlayout for a
GridBagLayout, but the columns in the JTable don't resize at all using the
method mentioned above.

Just wondered if a) I'm doing anything obviously wrong, or b) anyone else
has an example of formatting column widths in a JTable using 1.4.

Thanks for any assistnace,

Mark

Keywords & Tags: xylayout, jtable, java

URL: http://java.itags.org/java-newer/109506/
 
«« Prev - Next »» 6 helpful answers below.
On Tue, 24 Aug 2004 13:41:22 +0100, Mark wrote:

> The scroll pane previously used an
> XYLayout


What 'XYLayout'? I Googled and found lot's
of references, but there seemed to be various ones..

A fully qualified classname ( com.badlayouts.XYLayout )
might be better, or an specific URL, might be better..

> I've subsequently experienced problems with the XYLayout


Well.. an 'XYLayout', if I guess correctly how
it works, is probably worse than a null Layout..

null Layout's allow you to put specific components
in specific positions, and are terrible, non-cross
platform, not future/past Java version friendly...

OTOH, XYLayout would have much the same end results,
only it might lull you into believing that everything
should be OK because you have a Layout.

If this is a common Layout it is best to be specific
where you got it, there may be people willing/able
to assist.

Ultimately though, I recommend you work with Sun
standard API Layouts if you are a beginner. Once
you get the hang of them you realise that the null
and other 'exact' positioning layouts are
(largely) unnecessary.

HTH
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

andrew_thompson | Tue, 29 Apr 2008 20:06:00 GMT |

>> The scroll pane previously used an
> What 'XYLayout'? I Googled and found lot's
> of references, but there seemed to be various ones..


Apologies for not fully qualifying the class. It is
oracle.jdeveloper.layout.XYLayout, as I initially developed the application
in JDeveloper using 1.3. Now that I'm using 1.4 to make some changes,
whenever I try and run the app I get an "Unsupported major.minor version
48.0" error because the XYLayout class has been updated in the new version
of JDeveloper. Hence the need to use a different layout.

Thanks,

Mark

mark | Tue, 29 Apr 2008 20:07:00 GMT |

On Tue, 24 Aug 2004 13:41:22 +0100, Mark
<mark.harris.nospam...ukonline.co.uk.nospam> wrote:

> Hello,
> I'm experiencing problems with a JTable & assorted layouts.
> My Java application displays a number of records returned from a
> database in
> a JTable, which is held in a JScrollPane. The scroll pane previously
> used an
> XYLayout to display the JTable, and I used a method taken from
> http://www.chka.de/swing/table/cell-sizes.html to make the table's
> columns
> as wide as the widest item of data or column header.
> I've subsequently experienced problems with the XYLayout (moving from
> 1.3 to
> 1.4) and, as such, need to change the layout for the scroll pane for
> something else. I've tried to replace the scroll pane's XYlayout for a
> GridBagLayout, but the columns in the JTable don't resize at all using
> the
> method mentioned above.
> Just wondered if a) I'm doing anything obviously wrong, or b) anyone else
> has an example of formatting column widths in a JTable using 1.4.
> Thanks for any assistnace,
> Mark
>


XYLayout is a layout manager supplied with Borland's JBuilder product.
Understandably, it is used heavily by the GUI-builder included in
JBuilder. However, if you are thinking of deploying a Java application
using XYLayout, you would have to include the appropriate JBuilder jar
file which, as I discovered, breaches the JBuilder license. I therefore
STRONGLY advise against using XYLayout for anything to be deployed out of
the JBuilder license environment!

richard_chrenko | Tue, 29 Apr 2008 20:08:00 GMT |

To be honest, the XYLayout issue is somewhat of a red herring - I'm going to
remove it regardless. Hence the main thrust of my question is how to size
columns of a JTable to fit the enclosed data/table headers in Java 1.4.

Thanks,

Mark

mark | Tue, 29 Apr 2008 20:09:00 GMT |

On Tue, 24 Aug 2004 15:03:28 +0100, Mark wrote:

> To be honest, the XYLayout issue is somewhat of a red herring - I'm going
to
> remove it regardless.


Good move.

>...Hence the main thrust of my question is how to size
> columns of a JTable to fit the enclosed data/table headers in Java 1.4.


Now that is a more comprehensible aim (in a
poorly titled thread).

Unfortunately I am not that experienced
with JTables.. Anybody?
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

andrew_thompson | Tue, 29 Apr 2008 20:10:00 GMT |

"Mark" <mark.harris.nospam...ukonline.co.uk.nospam> writes:

> I've tried to replace the scroll pane's XYlayout for a
> GridBagLayout, but the columns in the JTable don't resize at all
> using the method mentioned above.


XYLayout was a "hack" that Borland introduced before they added
support for using a null layout in the designer. See if JDeveloper
also supports setting layout to null - then you should be able to size
the JTable as you see fit.

> Just wondered if a) I'm doing anything obviously wrong, or b) anyone
> else has an example of formatting column widths in a JTable using
> 1.4.


You can turn off auto-resizing and set column widths explicitly.

toriver_wilhelmsen_teamb_ | Tue, 29 Apr 2008 20:11:00 GMT |

Java in Newer Hot Answers

Java in Newer New questions

Java in Newer Related Categories