Thread View: borland.public.jbuilder.java.swing
1 messages
1 total messages
Started by arunsivaprakash
Wed, 12 Apr 2006 04:38
Java Swings: Adding JButton to JFrame in Jbuilder
Author: arunsivaprakash
Date: Wed, 12 Apr 2006 04:38
Date: Wed, 12 Apr 2006 04:38
98 lines
4011 bytes
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) {
}
}
}
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