Issue regarding adding Container on very Swing Page

public class POSToolBar extends JFrame {

/**
 * Launch the application.
 */
private BrowserToolBar toolBar;

public POSToolBar() {
    super("POS");
    Container content = getContentPane();
    content.setBackground(Color.white);
    toolBar = new BrowserToolBar();
    content.add(toolBar, BorderLayout.NORTH);
    pack();
    setVisible(true);
}
}

The above code generates a tool bar for me. Now I want to use this Tool Bar on every other swing page. I inherit/extends this class and use frame.add(new POSToolbar()) but it shows me an exception 'java.lang.IllegalArgumentException: adding a window to a container' How can I add this tool bar on my other swing pages ?

Answers


It must extend JToolBar not a JFrame if you want to use it in other classes.

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.*;

public class TestApplication extends JFrame {
    public static void main(String [] a){
        TestApplication ta = new TestApplication();
        TBar t = new TBar();
        ta.setLayout(new BorderLayout());
        ta.add(t,BorderLayout.NORTH);
        ta.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ta.setPreferredSize(new Dimension(400,300));
        ta.pack();
        ta.setVisible(true);
    }
}

class TBar extends JToolBar{
    JButton b = new JButton("Hello");

    public TBar(){
        add(b);
    }
}

Need Your Help

Pointer of byte array

pointers vb6 casting

So, I'm basically looking to know how to turn this

Deconstructing/Hacking NodeJs

javascript node.js operating-system

I am trying to understand Node internal workings and am at a point where I am not able to piece together how Node, which is written in js, hooks/binds into the low level system calls written in C/C...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.