当前位置: 技术问答>java相关
JInternalFrame 界面上的控件怎么显示
来源: 互联网 发布时间:2017-04-08
本文导语: 我现在可以显示 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.*; impo...
我现在可以显示 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.*;
/**
*
*
*
*
* @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));
}
}
是怎么回事?
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.*;
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @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));
}
}
|
以下是我修改以后的例子:
package internalframedemo;
/**
*
*
*
*
* @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);
}
}
package internalframedemo;
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @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);
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。