Solved

Can titlebar of JInternalFrame be made disappear

Posted on 2001-09-12
10
421 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
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 105
nextBoolean(double p) for Random class 3 40
more than one jdk and one jre 1 41
Chrome and Firefox Java 5 29
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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 …

776 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