File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Adding Components in to JInternalFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding Components in to JInternalFrame" Watch "Adding Components in to JInternalFrame" New topic
Author

Adding Components in to JInternalFrame

Hrishikesh K Nandanwar
Greenhorn

Joined: Feb 08, 2007
Posts: 5
Hi,
I have two classes
1)InternalFrameDemo.java
2)EnterDataFrame.java
I tried a lot but not able to add components (JButton,JLabel) to the JInternalFrame (EnterDataFrame.java)
Can anybody please provide me a solution.

import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
import javax.swing.KeyStroke;

import java.awt.event.*;
import java.awt.*;


public class InternalFrameDemo extends JFrame
implements ActionListener {
JDesktopPane desktop;
EnterDataFrame frame;

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

//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);

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

//Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
}

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

//Set up the lone menu.
JMenu menu = new JMenu("Menu");
menu.setMnemonic(KeyEvent.VK_D);
menuBar.add(menu);

//Set up the first menu item.
JMenuItem menuItem = new JMenuItem("Enter Data");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.ALT_MASK));
menuItem.setActionCommand("new");
menuItem.addActionListener(this);
menu.add(menuItem);

//Set up the second menu item.
menuItem = new JMenuItem("Quit");
menuItem.setMnemonic(KeyEvent.VK_Q);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_Q, ActionEvent.ALT_MASK));
menuItem.setActionCommand("quit");
menuItem.addActionListener(this);
menu.add(menuItem);

return menuBar;
}

//React to menu selections.
public void actionPerformed(ActionEvent e) {
if ("new".equals(e.getActionCommand())&&((frame == null)||(frame.isClosed()))) { //new

createEnterDataFrame();
} else { //quit
//quit();
}
}

//Create a new internal frame.
protected void createEnterDataFrame() {
frame = new EnterDataFrame();
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}

//Quit the application.
protected void quit() {
System.exit(0);
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
InternalFrameDemo frame = new InternalFrameDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Display the window.
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}




import javax.swing.*;
import javax.swing.JInternalFrame;
import java.awt.event.*;
import java.awt.*;

/* Used by InternalFrameDemo.java. */
public class EnterDataFrame extends JInternalFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;

public EnterDataFrame() {
super("Enter Data",
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable

//Set up the GUI.

show();
setSize(300,300);

}


}


Thanks,<br />Hrishikesh K Nandanwar
Terry Ong
Ranch Hand

Joined: Apr 07, 2006
Posts: 50
Try this.








Please refer to the follow too.
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JInternalFrame.html

JComponent c = (JComponent) internalFrame.getContentPane();
c.add(new JButton(), BorderLayout.NORTH);
c.add(new JButton(), BorderLayout.CENTER);



One last thing.
Be kind to us, indent your code and use the UBB code tags.
Thanks
Hrishikesh K Nandanwar
Greenhorn

Joined: Feb 08, 2007
Posts: 5
Its working fine.
I will definatly do the proper indentation.
Thanks a lot.
Terry Ong
Ranch Hand

Joined: Apr 07, 2006
Posts: 50
You're welcome.
[ February 08, 2007: Message edited by: Terry Ong ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding Components in to JInternalFrame
 
Similar Threads
mnemonics are not getting focus for the menubar
adding an InternalFrameListener to a JMenu Item
help with GUI practice
JTextArea append() not working?
Adding JMenuBar, after user Authentication.. Please Help