Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2003

Tip: Looking for answers? Try searching our database.

add JPanel and JLabel on JButton

Thread view: 
Robert Ludewig - 12 Dec 2003 10:56 GMT
Hello,
I need to to rather complex layouting on a JButton. I didn`t find a
way to do that with html-formatting.
How could I make a Jbutton capable of taking JPanels and JLabels ? I
porbally have to subclass JButton ... (?) But how do I add this kind
of functionality? What methods do I need to override and what should I
put there ?
Andrew Thompson - 12 Dec 2003 11:24 GMT
> Hello,
> I need to to rather complex layouting on a JButton. I didn`t find a
[quoted text clipped - 3 lines]
> of functionality? What methods do I need to override and what should I
> put there ?

Why not just make an image of the JPanel
and use it as an icon for the button?

What is it you want to put in the panel?

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
VisionSet - 13 Dec 2003 01:01 GMT
> Hello,
> I need to to rather complex layouting on a JButton. I didn`t find a
[quoted text clipped - 3 lines]
> of functionality? What methods do I need to override and what should I
> put there ?

JButton is a container so you can add components in the same way you would
normally.
The only real problem is that the action event usually received by the
JButton will only fire if you 'miss' the components on top, clearly
impossible with a GridLayout.

So you will have to delegate the events from your JPanels's & JLabel's

This will mean adding a mouse listener and/or key listener to your JPanels's
& JLabel's

detect the event in those listener methods, and perform a
yourButton.doClick() on it.

I haven't done this, but looking at the API this is the approach I'd take
first.

Signature

Mike W

Robert Ludewig - 13 Dec 2003 08:18 GMT
> JButton is a container so you can add components in the same way you would
>normally.

JButton button = new Button ();
button.add.(new JPanel());

gives a nullpointerexception
Andrew Thompson - 13 Dec 2003 09:00 GMT
> > JButton is a container so you can add components in the same way you would
> >normally.
>
> JButton button = new Button ();
> button.add.(new JPanel());

Was that a typo?  Try..
button.add(new JPanel());

[ look carefully ]

> gives a nullpointerexception

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Harald Hein - 13 Dec 2003 15:30 GMT
> I need to to rather complex layouting on a JButton. I didn`t find
> a way to do that with html-formatting.
> How could I make a Jbutton capable of taking JPanels and JLabels ?
> I porbally have to subclass JButton ... (?) But how do I add this
> kind of functionality? What methods do I need to override and what
> should I put there ?

The whole thing sounds like a rather dump idea. You want to place
components on a JButton? Why? Are you going for the prize of the most
messed up GUI?
Andrew Thompson - 13 Dec 2003 15:56 GMT
...
> > How could I make a Jbutton capable of taking JPanels and JLabels ?
...
> The whole thing sounds like a rather dump idea. You want to place
> components on a JButton? Why? Are you going for the prize of the most
> messed up GUI?

No, no Harald!  Imagine a JTextArea as the
component - as the user clicks in it, the app
can trigger random text to be inserted..

The user will be messing with their mouse,
checking the keyboard, going mad trying
to figure why the program is behaving so
strangely.

It'll be funny, ..trust me!       ;-)

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Robert Ludewig - 13 Dec 2003 21:53 GMT
it is importan to be able to add jpanels and other components on a jbutton
to have some complex layout design on a jutton. for example text wrapping
arond an image. With the text having different sizes and fonts
VisionSet - 14 Dec 2003 00:01 GMT
> it is importan to be able to add jpanels and other components on a jbutton
> to have some complex layout design on a jutton. for example text wrapping
> arond an image. With the text having different sizes and fonts

That can be accomplished in html with css style elements float and font.
Can swing text components use css?
Sounds like a horrible button.

Signature

Mike W

Harald Hein - 14 Dec 2003 07:32 GMT
> it is importan to be able to add jpanels and other components on a
> jbutton to have some complex layout design on a jutton.

It is not important, it is bullshit. A button has a special purpose,
which is not doing some compley layouting, but just occupying some
small screen estate, presenting a label and maybe an icon (advanced
feature) and an opportunity to click on it.

It is your own wishful thinking and an apparent attempt to relaize a
rather awful design that makes you think it is an important must-have
feature to add components to a button.

Unless you step back, look at your design and change it to something
useful you will not solve that problem. Which is a home-made problem,
only existing becaus of your design.

> for example text wrapping arond an image. With the text having
> different sizes and fonts

In a button? Get real man. How awful do you want your GUI to look like
and behave? How large should this button from hell become? Occupying
1/3 of the screen just because you want to have a super fancy label?
Should it become so large that users feel the urge to punch this
abomination with a fist?
Robert Ludewig - 15 Dec 2003 00:25 GMT
ok, I tell you what I intended , it is very simple put doesn't seem to be
possible with plain html:

The buttonlabel shall have one character in its very center. And another one
at the top left corner (in another font and a very small fontsize).
The small character in that corner must be totally at the top and left
border of the button, leaving no white space between the edge of the button
and  the charcter.
When the button gets resized the small char must still be aligned that way
and the big char must stay in the center ...
I haven't found a way to fromat that in html, there is ALWAYS some white
space between the samll char and the edge of the button. I tried <div> and
<table> nothing.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.