JInternalFrame 界面上的控件怎么显示

asdmusic8 2002-12-26 03:47:00
我现在可以显示 MyJInternalFrame 界面了, 但是我加在上面的控件看不到
是怎么回事?

package untitled3;

import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.print.*;
import javax.swing.event.*;
import java.awt.print.Book.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.border.*;
import com.borland.jbcl.layout.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/

public class MyJInternalFrame extends JInternalFrame {
private JDesktopPane JDesktop=new JDesktopPane();
private JMenuBar menubar =new JMenuBar();
private Vector objects =new Vector();
private Font tabFont =new Font("MonoSpaced",Font.PLAIN,12);
private JButton pageSetupBtt =new JButton("页面设置"); //看不到按钮
private JButton printBtt =new JButton("打印");
private JButton printPreviewBtt=new JButton("预览");
private JButton cmdBig =new JButton("放大");
private JButton cmdSmall =new JButton("缩小");
private JButton preBtt =new JButton("上一页");
private JButton nextBtt =new JButton("下一页");
private JButton cmdExit =new JButton("返回");
private JLabel lblVisible =new JLabel("");
private JLabel lblPageInfo =new JLabel(" ");

private JPanel bttPanel =new JPanel();
private FlowLayout flowLayout1 = new FlowLayout();
private GridBagLayout gridBagLayout1 = new GridBagLayout();
private GridBagLayout gridBagLayout2 = new GridBagLayout();

public MyJInternalFrame() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
this.setClosable(true);
this.setContentPane(JDesktop);
this.setMaximizable(true);
this.setResizable(true);
this.setEnabled(true);
this.setNextFocusableComponent(JDesktop);
this.setToolTipText("");
setSize(new Dimension(720, 540));
try{setMaximum(true);}catch(Exception e){}
this.getContentPane().setLayout(gridBagLayout1);
JDesktop.setBorder(BorderFactory.createLineBorder(Color.black));
JDesktop.setSelectedFrame(this);
JDesktop.setLayout(gridBagLayout2);

bttPanel.setLayout(flowLayout1);
bttPanel.setBorder(BorderFactory.createLineBorder(Color.black));

bttPanel.add(lblPageInfo);
bttPanel.add(pageSetupBtt);
bttPanel.add(printBtt);
bttPanel.add(printPreviewBtt);
bttPanel.add(cmdBig);
bttPanel.add(cmdSmall);
bttPanel.add(preBtt);
bttPanel.add(nextBtt);
bttPanel.add(cmdExit);
JDesktop.add(lblVisible, new GridBagConstraints(0, 0, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 0.0, 0.0
,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(-1, -1, 0, 0), 0, 0));
JDesktop.add(bttPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(-1, -1, 475, 0), 136, -4));
JDesktop.add(lblVisible);
JDesktop.add(bttPanel, null);

pageSetupBtt.setMnemonic('S');
printPreviewBtt.setMnemonic('V');
cmdBig.setMnemonic('=');
preBtt.setMnemonic(',');
cmdSmall.setMnemonic('-');
nextBtt.setMnemonic('.');
printBtt.setMnemonic('P');
cmdExit.setMnemonic('X');

setJMenuBar(menubar);
menubar.add(bttPanel);
this.getContentPane().add(JDesktop, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 1, 0), 716, 512));
}
}
...全文
60 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weimenren 2002-12-26
  • 打赏
  • 举报
回复
以下是我修改以后的例子:



package internalframedemo;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

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.*;

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

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



frame.setVisible(true); //necessary as of 1.3; OK to use before
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}

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


package internalframedemo;

import javax.swing.JInternalFrame;

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

public class MyInternalFrame extends JInternalFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;
// public JButton button = new JButton();
public MyInternalFrame() {
super("Document #" + (++openFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable

//...Create the GUI and put it in the window...

//...Then set the window size or call pack...
setSize(300,300);


// add(button);

//Set the window's location.
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
}
}


weimenren 2002-12-26
  • 打赏
  • 举报
回复
public class JInternalFrame
extends JComponent
implements Accessible, WindowConstants, RootPaneContainer


weimenren 2002-12-26
  • 打赏
  • 举报
回复
JComponent c = (JComponent) internalFrame.getContentPane();
c.add(new JButton(), BorderLayout.NORTH);
c.add(new JButton(), BorderLayout.CENTER);

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧