🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Java Swings: Adding JButton to JFrame in Jbuilder

#152
From: arunsivaprakash
Date: Wed, 12 Apr 2006 04:38
98 lines
4011 bytes
Dear All,

I have a problem in the following code.....I was unit testing the code
from main(). I have the FaMain base class for creating the window with
certain features. So I need all my child windows to inherit FaMain
class. Similarly, I need FaButton as base class instead of JButton.

But even after creating two buttons but1 & but2 only the second button
but2 is getting appeared......Please help me.......


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class FaButton extends JPanel {

  JButton jButton1;
  FaMain fa;
  static JFrame jf;
  public FaButton() {
    jf = new FaMain().jfFaMain;
    jButton1.setText("Sample");
    jButton1.setBounds(new Rectangle(229, 122, 59, 25));
    jButton1.setOpaque(true);
    jButton1.setVisible(true);
    jf.getContentPane().add(jButton1);
  }
   public FaButton(JFrame jf, String title, char Mnemonic, String
ToolTipText )throws Exception {
    this.jf = (jf == null)? new JFrame(Console.title(fa)) : jf;
    jButton1 = new JButton();
    jButton1.setText(title);
    jButton1.setMnemonic(Mnemonic);
    jButton1.setToolTipText(ToolTipText);
    jButton1.setBounds(new Rectangle(0, 0, 100, 100));
    jButton1.setOpaque(true);
    jButton1.setEnabled(true);
    add(jButton1);
    jf.getContentPane().add(this);
 }
 public FaButton(JFrame jf, int x, int y, int width, int height, String
title, char Mnemonic, String ToolTipText )throws Exception {
    this.jf = (jf == null)? new JFrame(Console.title(fa)) : jf;
   jButton1 = new JButton();
   jButton1.setText(title);
   jButton1.setMnemonic(Mnemonic);
   jButton1.setToolTipText(ToolTipText);
   jButton1.setBounds(new Rectangle(x, y, width, height));

   jButton1.setAlignmentX(x);
   jButton1.setAlignmentY(y);

   jButton1.setOpaque(true);
   jButton1.setEnabled(true);
   jButton1.setVisible(true);

   add(jButton1, null);

   jf.getContentPane().add(this);

   jButton1.setVisible(true);

   jButton1.revalidate();
   jButton1.repaint();
}
  public static void main(String[] args) {
    try {
      FaMain faMain = new FaMain();
      JFrame jj= faMain.jfFaMain;

      FaButton but1 = new FaButton(jj, 500, 500, 100, 100, "My
Button1", 'M', "This is a button");
      FaButton but2 = new FaButton(jj, 200, 200, 100, 100, "My
Button2", 'M', "This is a button");

      Component[] comp =
jf.getRootPane().getContentPane().getComponents();

System.out.println(jf.getRootPane().getContentPane().getComponentCount());

      for (int i = 0; i < comp.length; i++) {
        System.out.println(comp[i].getClass().getName());
      }
    }
    catch (Exception ex) {
    }
  }
}
Technical Details
Message-ID: <1144816731.245460.16210@v46g2000cwv.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!v46g2000cwv.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,d477cf67ebb2ad7c,start
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!v46g2000cwv.googlegroups.com!not-for-mail
From: arunsivaprakash@gmail.com
Newsgroups: borland.public.jbuilder.java.swing
Subject: Java Swings: Adding JButton to JFrame in Jbuilder
Date: 11 Apr 2006 21:38:51 -0700
Organization: http://groups.google.com
Lines: 99
Message-ID: <1144816731.245460.16210@v46g2000cwv.googlegroups.com>
NNTP-Posting-Host: 203.197.151.21
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1144816739 10943 127.0.0.1 (12 Apr 2006 04:38:59 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 12 Apr 2006 04:38:59 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1),gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 www.uaeexchangeindia.co.in:3128 (squid/2.5.STABLE1)
Complaints-To: groups-abuse@google.com
Injection-Info: v46g2000cwv.googlegroups.com; posting-host=203.197.151.21;
   posting-account=8meLeg0AAADX8D14EjRdULtu0upk6iLd