Solved

Can titlebar of JInternalFrame be made disappear

Posted on 2001-09-12
10
407 Views
Last Modified: 2008-01-09
Hi ,
i want the titlebar of JInternalFrame to be disappeared and in that place i want to add a toolbar in that place,
please can anyone help me

thankyou
kiran
0
Comment
Question by:globalkiran
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
Then you will have not a JInternalFrame.
0
 

Expert Comment

by:lawpan
Comment Utility
use JWindow
at the same way as JInternalframe
JWindow are normally used as splashscreens.
JWindow myWind = new JWindow();
myWind.add(toolbar);

        myWind.setVisible(false); or show()
0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
Yep, the problem with JWindow is that it cannot be moved or added to a JDesktopPane.
0
 

Expert Comment

by:lawpan
Comment Utility
Yes, this was quite obvouis if you remove the titlebar.
Then you have to implement moving / resize code in another manner. JDesktopPane is not used. The user are using XComponent and JToolbar in his/her description.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 100 total points
Comment Utility
You can add a JToolBar to a JInternalFrame the same way that you would add it to a JFrame. In both cases, you create a JToolBar and add it to the NORTH area of the frame's content pane.

    JInternalFrame frame = new JInternalFrame();
    JToolBar toolBar = new JToolBar();
    // customize the toolBar
    frame.getContentPane().add(toolBar, BorderLayout.NORTH);

Removing the titlebar from a JInternalFrame is a little trickier. For this you need to get the UI delegate of the frame and set the Component displayed in it's north pane to null. Don't worry, this 'north' pane is different than the 'north' area of the content pane.

    ((javax.swing.plaf.basic.BasicInternalFrameUI)frame.getUI()).setNorthPane(null);

Here is a complete working example -- albeit not well written. I hacked it together from code in the Java Tutorial. Look at the createFrame method for the bits that specifically address your question.

The sample code was take from these tutorial examples:
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/InternalFrameDemo.java
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/MyInternalFrame.java
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/ToolBarDemo.java
You can get the images here:
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/images/right.gif
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/images/middle.gif
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/images/left.gif

---------- InternalFrameDemo.java ----------
import javax.swing.*;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import java.awt.event.*;
import java.awt.*;

public class InternalFrameDemo extends JFrame {
    JDesktopPane desktop;

    public InternalFrameDemo() {
        super("InternalFrameDemo");

        //Make the big window be indented 50 pixels from each edge
        //of the screen.
        int inset = 50;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(inset, inset,
            screenSize.width - inset*2,
            screenSize.height-inset*2);

        //Quit this app when the big window closes.
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        //Set up the GUI.
        desktop = new JDesktopPane(); //a specialized layered pane
        createFrame(); //Create first window
        setContentPane(desktop);
        setJMenuBar(createMenuBar());

        //Make dragging faster:
        desktop.putClientProperty("JDesktopPane.dragMode", "outline");
    }

    protected JMenuBar createMenuBar() {
        JMenuBar menuBar = new JMenuBar();

        JMenu menu = new JMenu("Document");
        menu.setMnemonic(KeyEvent.VK_D);
        JMenuItem menuItem = new JMenuItem("New");
        menuItem.setMnemonic(KeyEvent.VK_N);
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                createFrame();
            }
        });
        menu.add(menuItem);
        menuBar.add(menu);

        return menuBar;
    }

    protected void createFrame() {
        MyInternalFrame frame = new MyInternalFrame();

        // REMOVE THE FRAME'S TITLEBAR
        BasicInternalFrameUI ui = (BasicInternalFrameUI)frame.getUI();
        ui.setNorthPane(null);

        // ADD THE TOOLBAR
        JToolBar tb = new JToolBar();
        addButtons(tb);
        frame.getContentPane().add(tb, BorderLayout.NORTH);

        frame.setVisible(true); //necessary as of kestrel
        desktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

   
    protected void addButtons(JToolBar toolBar) {
        JButton button = null;

        //first button
        button = new JButton(new ImageIcon("images/left.gif"));
        button.setToolTipText("This is the left button");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                displayResult("Action for first button");
            }
        });
        toolBar.add(button);

        //second button
        button = new JButton(new ImageIcon("images/middle.gif"));
        button.setToolTipText("This is the middle button");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                displayResult("Action for second button");
            }
        });
        toolBar.add(button);

        //third button
        button = new JButton(new ImageIcon("images/right.gif"));
        button.setToolTipText("This is the right button");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                displayResult("Action for third button");
            }
        });
        toolBar.add(button);
    }

    protected void displayResult(String actionDescription) {
        System.out.println(actionDescription + "\n");
    }


    public static void main(String[] args) {
        InternalFrameDemo frame = new InternalFrameDemo();
        frame.setVisible(true);
    }
}
---------- end ----------

Best regards,
Jim Cakalic
0
 

Author Comment

by:globalkiran
Comment Utility
Thanks  jim_cakalic,we got your code,
we implemented it successfully.
Thankyou onceagain
Regards
kiran
0
 
LVL 19

Expert Comment

by:Jim Cakalic
Comment Utility
Glad to be of assistance :-)
0
 
LVL 20

Expert Comment

by:Venabili
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for jim_cakalic

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venabili
EE Cleanup Volunteer
0
 
LVL 19

Expert Comment

by:Jim Cakalic
Comment Utility
OK. Thanks.
Jim
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now