🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #1376

Re: JButton auto resize??

#1376
From: Rudy
Date: Wed, 17 Dec 2003 07:41
86 lines
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
Technical Details
Message-ID: <3fe008a8@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!newsfeed.media.kyoto-u.ac.jp!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3fca70a4$1@newsgroups.borland.com> <3fcaeb5a@newsgroups.borland.com> <3fde40c0$1@newsgroups.borland.com> <3fde639f$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,d747d5f574c277f5
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2003-12-16 23:57:53 PST
Reply-To: "Rudy" <rhentzen@hotmail.com>
From: "Rudy" <rhentzen@hotmail.com>
Newsgroups: borland.public.jbuilder.java.swing
References: <3fca70a4$1@newsgroups.borland.com> <3fcaeb5a@newsgroups.borland.com> <3fde40c0$1@newsgroups.borland.com> <3fde639f$1@newsgroups.borland.com>
Subject: Re: JButton auto resize??
Date: Wed, 17 Dec 2003 07:41:18 -0000
Lines: 88
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 81.86.182.21
Message-ID: <3fe008a8@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1071646888 81.86.182.21 (16 Dec 2003 23:41:28 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!newsfeed.media.kyoto-u.ac.jp!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail