473,412 Members | 4,594 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

GridBagLayout

Hi everyone
I'm trying to develop an applet using JApplet. As the layout manager I
decided to use GridBagLayout. My layout will consist mainly of 7 JComboBox's
in a single row and one JTable beneath them.
My problem is, I can't even put the JComboBox's on the top of the
Applet. Everytime I do the add method, they stay put in the middle of the
Applet. I've tried setting GridBagConstraints.gridy = 0 but it didn't do me
any good.

Any help would be welcome, especially code examples or links
Thank you very much
Rui Pacheco
Jul 17 '05 #1
1 5006
"Rui Pacheco" <ru*********@viaverde.pt_NOSPAM> wrote in message news:<10***************@news.oninet.pt>...
Hi everyone
I'm trying to develop an applet using JApplet. As the layout manager I
decided to use GridBagLayout. My layout will consist mainly of 7 JComboBox's
in a single row and one JTable beneath them.
My problem is, I can't even put the JComboBox's on the top of the
Applet. Everytime I do the add method, they stay put in the middle of the
Applet. I've tried setting GridBagConstraints.gridy = 0 but it didn't do me
any good.

Any help would be welcome, especially code examples or links
Thank you very much
Rui Pacheco


Wow, I guess having experience with other clunky GUI toolkits (like Xt
and Motif), GridBagLayout didn't seem too bad. I did like the way you
"attached" widgets to each other in those toolkits, though, like
"attachLeft" and "attachOppositeRight", stuff like that. I don't
really remember, it's been years.

Anyhow, from your description, I have to ask if you really need a
gridbag layout? Why would you want it? You know the way to getting
the interface exactly the way you want it is to make it as object
oriented as the code.

For example, assuming you want to use gridbag to make all the
comboboxes the same width, you might want to make two gridbags... one
for the top component, which might be a panel with a gridbag layout
with dimensions of 1 row and seven columns - make sure you set the
weights and so forth equally, and your fill is horizontal.

Then you have another gridbag, 2 rows by 1 column. The first row is
the jpanel you just created. This should also have a horizontal fill
to stretch to the width when the user resizes the window. The second
row would have the jtable - with fill being "BOTH", so that it
stretches to width and height. You may also need to set the weights
(top would have a Y weight of 0, the bottom 1, I think).

There's other ways to do it. Boxes is a nice way - create a parent
vertical box, then add a horizontal box with the comboboxes as the top
component, then the JTable below. You may need to set some options so
that it doesn't "wrap."

Now, I'm beginning to see your problem might be that the applet window
is larger than the UI you are creating, in which case your UI is
appearing in the center. Make sure your applet has the same
dimensions as you've defined in the web page. Also, don't judge the
layout until you have your jtable. I haven't really done that much
with applets, I usually do full applications, so the interaction with
the webbrowser might be an issue.

Seriously, though, what I find with "easy" layouts/toolkits is that
the developer takes short cuts and does things like making interfaces
that can't be resized - or if they are, you get unexpected behavior
(like a Jtable doesn't expand to fit, or a file selection doesn't
expand to fit - you just get blank space). As a user I find those
things most annoying, so as a developer I avoid them. Most of the
toolkits I've used that allow really flexible UI's, UI's where you can
define the behavior exactly the way you want it (and behave exactly
the way a user should reasonably expect, especially w.r.t. resizing)
are necessarily complex because they need to be flexible. Most of
them start to make sense after you've used them a few times, and
figured out how to do something that seemed awkward.

The best thing is to keep in mind that you can use multiple layouts in
a single application - one overall layout with a bunch of smaller
layouts, and often even smaller layouts within those. Always keep in
mind user behavior. I've have users whose habit is to make every
window fullscreen, wether it's needed or not. You just never know.
You can take the cheap way out and make it so your window can't be
resized, but that's pretty bad style, IMO.

Also, one thing I did discover with applets (use at your own risk), is
you can open a new window on the users machine from within the applet.
That way the user gets the flexibility of a native window, instead of
being confined in the browser. Use at your own risk, though, strange
things can happen when they open a new page while your application is
running, or hit the back button or something. Not very pretty.

Maybe I'll make some web pages about GridBag. I know some others have
said they're working on them. Regardless, let me know if you can't
get it to work.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Merlin_1102 | last post by:
I have read previous posts on the gridbaglayout and none seem to answer my questions (sorry if any of these have been aske dI really did search and found one large thread which took me an hour to...
2
by: Pablo | last post by:
Could someone please help me to figure out how to use subj? I need to arrange 12 buttons in four rows - four in 1st row, two in 2nd, another two in 3rd , and last four in 4th row. I follow...
0
by: Martin | last post by:
Hi All, I am a relative newbie to Java / Applets, but am despirately after some help ! I have got the following code, which is basically a listing with button items along the sides, allowing...
0
by: Peter Wieser | last post by:
this short program does not do as it should!!! when you resize the frame, the weights (3 and 1) would not stay the same. why??? import java.applet.Applet; import java.awt.event.*; import...
1
by: python473 | last post by:
Friends - I have tried to do abolute positioning using gridbaglayout, but am having no success in jython. One book I have been referencing says that it only works with JPanels. Could someone post a...
1
by: Tony Johansson | last post by:
Hello experts! As this program is now it's works perfectly when running as a application or as an Applet. Now to my question if I just change this row "public class Converter extends Applet "...
7
by: sreenulanka | last post by:
please help me in my forum i have labels and textareas .iwant to add textarea components dyanamically when i am clicking the button.please help me import java.awt.*; import javax.swing.*;...
0
by: Didje | last post by:
Hi, I'm trying to design a kind of calculator GUI using gridbaglayout. At the top of the calculator will be a couple of menus and then will come the section with all the buttons etc. Initially, I...
5
by: cblank | last post by:
I'm having some trouble with my inventory program. Its due tom and my teacher is not wanting to help. He keeps giving me a soluction that is not related to my code. I have everything working except...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.