Thread View: borland.public.jbuilder.java.swing
11 messages
11 total messages
Started by Rudy
Sun, 30 Nov 2003 22:35
JButton auto resize??
Author: Rudy
Date: Sun, 30 Nov 2003 22:35
Date: Sun, 30 Nov 2003 22:35
36 lines
2278 bytes
2278 bytes
I have the following code:
public void add(final JButton component) {
component.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
mComponent = component;
//mComponent.setBackground(Color.BLUE);
}
});
mComponent = component;
mComponent.setSize(w, h);
mComponent.setLocation(x, y);
mComponent.setMinimumSize(new Dimension(120, 120));
mComponent.setMaximumSize(new Dimension(150, 150));
mComponent.setPreferredSize(new Dimension(130, 130));
mComponent.setFont(new Font("Dialog", 0, 9));
mComponent.setBorder(BorderFactory.createEmptyBorder());
mComponent.setBackground(Color.WHITE);
mComponent.setMargin(new Insets(1, 1, 1, 1));
mComponent.setText(text);
mComponent.setVerticalAlignment(SwingConstants.TOP);
mComponent.setHorizontalAlignment(SwingConstants.CENTER);
mComponent.setIcon(logo2);
super.add(mComponent);
repaint();
}
the problem i am having is that i would like the button to resize depending
on what text is entered in the setText() method. I find that the button
uses the setSize method and always stays at this size but does not use the
set...Size methods. However if i remove the setSize method then the button
is not displayed. How can i ensure the button is size around the text
properly.
Thanks
Rudy
Re: JButton auto resize??
Author: pNichols
Date: Mon, 01 Dec 2003 07:26
Date: Mon, 01 Dec 2003 07:26
7 lines
1084 bytes
1084 bytes
Rudy wrote: > I have the following code: > > I did not see what Layout manager you are using for the container. Try FlowLayout for the LayoutManager for the container and all should be well.
Re: JButton auto resize??
Author: Rudy
Date: Mon, 15 Dec 2003 23:16
Date: Mon, 15 Dec 2003 23:16
16 lines
1509 bytes
1509 bytes
Hi, well what it is, is that i am trying to develop a design canvas in which the user can drag an drop buttons with different picture of different sizes, so i will be using the XYlayout manager. Thanks Rudy "pNichols" <paul@computer-logic.net> wrote in message news:3fcaeb5a@newsgroups.borland.com... > Rudy wrote: > > > I have the following code: > > > > > I did not see what Layout manager you are using for the container. Try > FlowLayout for the LayoutManager for the container and all should be well. >
Re: JButton auto resize??
Author: John McGrath [TeamB]
Date: Tue, 16 Dec 2003 00:45
Date: Tue, 16 Dec 2003 00:45
16 lines
1481 bytes
1481 bytes
On 12/15/2003 at 6:16:01 PM, Rudy wrote:
> Hi, well what it is, is that i am trying to develop a design canvas
> in which the user can drag an drop buttons with different picture of
> different sizes, so i will be using the XYlayout manager.
What XYConstraints do you use when you add the button to its container?
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: JButton auto resize??
Author: Rudy
Date: Wed, 17 Dec 2003 07:41
Date: Wed, 17 Dec 2003 07:41
86 lines
3623 bytes
3623 bytes
Here is the code for my class,
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DesignPanel extends JPanel {
private JButton mComponent = null;
private ImageIcon icon;
private String text = null;
private Image logo1;
private Icon logo2;
private int x, y, w, h;
public DesignPanel() {
setLayout(null);
setBackground(Color.WHITE);
}
public void add(final JButton component) {
component.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
mComponent = component;
//mComponent.setBackground(Color.BLUE);
}
});
mComponent = component;
mComponent.setSize(w, h);
mComponent.setLocation(x, y);
mComponent.setMinimumSize(new Dimension(120, 120));
mComponent.setMaximumSize(new Dimension(150, 150));
mComponent.setPreferredSize(new Dimension(130, 130));
mComponent.setFont(new Font("Dialog", 0, 9));
mComponent.setBorder(BorderFactory.createEmptyBorder());
mComponent.setBackground(Color.WHITE);
mComponent.setMargin(new Insets(1, 1, 1, 1));
mComponent.setText(text);
mComponent.setVerticalAlignment(SwingConstants.TOP);
mComponent.setHorizontalAlignment(SwingConstants.CENTER);
mComponent.setIcon(logo2);
super.add(mComponent);
repaint();
}
public void setImageIcon(String URL){
System.out.println("In design " + URL);
icon = new ImageIcon(URL);
Image img = icon.getImage();
logo2 = (Icon)icon;
}
public void setImageText(String text){
this.text = text;
}
public void setCharact(int x, int y, int w, int h){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
}
I also dont suppose you could tell me how best to use the images and
imageIcons for buttons,
thanks for your time
Rudy
"John McGrath [TeamB]" <ng-b@JPMcGrath.net> wrote in message
news:3fde639f$1@newsgroups.borland.com...
> On 12/15/2003 at 6:16:01 PM, Rudy wrote:
>
> > Hi, well what it is, is that i am trying to develop a design canvas
> > in which the user can drag an drop buttons with different picture of
> > different sizes, so i will be using the XYlayout manager.
>
> What XYConstraints do you use when you add the button to its container?
>
> --
> Regards,
>
> John McGrath [TeamB]
>
> ---------------------------------------------------
> Before sending me e-mail, please read:
> http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: JButton auto resize??
Author: John McGrath [TeamB]
Date: Wed, 17 Dec 2003 23:39
Date: Wed, 17 Dec 2003 23:39
31 lines
2152 bytes
2152 bytes
On 12/17/2003 at 2:41:18 AM, Rudy wrote:
> > What XYConstraints do you use when you add the button to its
> > container?
> Here is the code for my class,
This is the line of code I was trying to get you to look at. You are
using an XYLayout, but you are not specifying an XYConstraint object
when you add it to the container.
> super.add(mComponent);
But that said, I really wonder why you are using XYLayout in the first
place. It sounds like you are trying to directly manage the size and
position of the buttons, so what does the layout manager do for you?
> I also dont suppose you could tell me how best to use the images and
> imageIcons for buttons,
Take a look at the Java Tutorial on the Sun web site. The Swing
section should cover this.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: JButton auto resize??
Author: Rudy
Date: Thu, 18 Dec 2003 19:02
Date: Thu, 18 Dec 2003 19:02
42 lines
2505 bytes
2505 bytes
Hi, thanks for the reply, I cannot see how i am using the XYLayout in the code i printed, but all I want to be able to do is allow a button to be sized based on its content. I all wrote setLayout(null) so i thought this would not give me a layout manager??? Thanks Rudy "John McGrath [TeamB]" <ng-b@JPMcGrath.net> wrote in message news:3fe0f730@newsgroups.borland.com... > On 12/17/2003 at 2:41:18 AM, Rudy wrote: > > > > What XYConstraints do you use when you add the button to its > > > container? > > > Here is the code for my class, > > This is the line of code I was trying to get you to look at. You are > using an XYLayout, but you are not specifying an XYConstraint object > when you add it to the container. > > > super.add(mComponent); > > But that said, I really wonder why you are using XYLayout in the first > place. It sounds like you are trying to directly manage the size and > position of the buttons, so what does the layout manager do for you? > > > I also dont suppose you could tell me how best to use the images and > > imageIcons for buttons, > > Take a look at the Java Tutorial on the Sun web site. The Swing > section should cover this. > > -- > Regards, > > John McGrath [TeamB] > > --------------------------------------------------- > Before sending me e-mail, please read: > http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: JButton auto resize??
Author: John McGrath [TeamB]
Date: Thu, 18 Dec 2003 22:01
Date: Thu, 18 Dec 2003 22:01
17 lines
1622 bytes
1622 bytes
On 12/18/2003 at 2:02:50 PM, Rudy wrote:
> > i will be using the XYlayout manager.
> I cannot see how i am using the XYLayout in the code
Yes, I see that now. I must compliment you on your very effective
use of misdirection. :o)
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: JButton auto resize??
Author: Rudy
Date: Thu, 18 Dec 2003 22:10
Date: Thu, 18 Dec 2003 22:10
44 lines
2562 bytes
2562 bytes
I have fixed it, i used the xyLayout with x,y,-1-1 so the width and height
are resized....thatnks for the help
Rudy
"Rudy" <rhentzen@hotmail.com> wrote in message
news:3fca70a4$1@newsgroups.borland.com...
> I have the following code:
>
> public void add(final JButton component) {
> component.addMouseListener(new MouseAdapter() {
> public void mousePressed(MouseEvent e) {
> mComponent = component;
> //mComponent.setBackground(Color.BLUE);
> }
> });
> mComponent = component;
> mComponent.setSize(w, h);
> mComponent.setLocation(x, y);
> mComponent.setMinimumSize(new Dimension(120, 120));
> mComponent.setMaximumSize(new Dimension(150, 150));
> mComponent.setPreferredSize(new Dimension(130, 130));
> mComponent.setFont(new Font("Dialog", 0, 9));
> mComponent.setBorder(BorderFactory.createEmptyBorder());
> mComponent.setBackground(Color.WHITE);
> mComponent.setMargin(new Insets(1, 1, 1, 1));
> mComponent.setText(text);
> mComponent.setVerticalAlignment(SwingConstants.TOP);
> mComponent.setHorizontalAlignment(SwingConstants.CENTER);
> mComponent.setIcon(logo2);
> super.add(mComponent);
> repaint();
> }
>
> the problem i am having is that i would like the button to resize
depending
> on what text is entered in the setText() method. I find that the button
> uses the setSize method and always stays at this size but does not use the
> set...Size methods. However if i remove the setSize method then the button
> is not displayed. How can i ensure the button is size around the text
> properly.
>
> Thanks
> Rudy
>
>
Re: JButton auto resize??
Author: Rudy
Date: Fri, 19 Dec 2003 16:20
Date: Fri, 19 Dec 2003 16:20
23 lines
2051 bytes
2051 bytes
Ha, well, when something soooo simple is giving soooooo much grief you forget what your doing. I planned to use XY, didnt use XY, then used XY and worked. Rudy "John McGrath [TeamB]" <ng-b@JPMcGrath.net> wrote in message news:3fe231d8$1@newsgroups.borland.com... > On 12/18/2003 at 2:02:50 PM, Rudy wrote: > > > > i will be using the XYlayout manager. > > > I cannot see how i am using the XYLayout in the code > > Yes, I see that now. I must compliment you on your very effective > use of misdirection. :o) > > -- > Regards, > > John McGrath [TeamB] > > --------------------------------------------------- > Before sending me e-mail, please read: > http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: JButton auto resize??
Author: Paul Furbacher
Date: Fri, 19 Dec 2003 19:12
Date: Fri, 19 Dec 2003 19:12
45 lines
2691 bytes
2691 bytes
Rudy wrote:
> Ha, well, when something soooo simple is giving soooooo much grief
> you forget what your doing. I planned to use XY, didnt use XY,
> then used XY and worked.
Has anyone mentioned that you should only
use XYLayout initially when you place
components on your panel, and _then_
switch to a standard Swing layout, such
as the GridBag?
It may be useful to re-read the section in
the JBuilder Help on how to temporarily
use the XYLayout to get your design started.
The section stresses that you should not
use XYLayout in your final design.
It's really in your best interest that
I'm suggesting this. If you stick with
the XYLayout, your users may well curse you,
and use words you don't want to hear with
regard to your UI design.
Yes, the GridBagLayout is initially difficult
and confusing, but once you master it, and
use the GridBag Assistant which JBuilder offers,
you'll be cruising, producing well-crafted and
admired UIs.
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://www.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads