Solved

Can titlebar of JInternalFrame be made disappear

Posted on 2001-09-12
10
467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 9

Expert Comment

by:Ovi
ID: 6476519
Then you will have not a JInternalFrame.
0
 

Expert Comment

by:lawpan
ID: 6476667
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
ID: 6476727
Yep, the problem with JWindow is that it cannot be moved or added to a JDesktopPane.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Expert Comment

by:lawpan
ID: 6476736
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
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 100 total points
ID: 6476981
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
ID: 6478545
Thanks  jim_cakalic,we got your code,
we implemented it successfully.
Thankyou onceagain
Regards
kiran
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 6479843
Glad to be of assistance :-)
0
 
LVL 20

Expert Comment

by:Venabili
ID: 8908874
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
ID: 8916631
OK. Thanks.
Jim
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

729 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