Tạo cửa sổ con nằm trong cửa sổ Tab chính trong Java - Dùng JInternalFame JDesktopPane TablePane Java Swing Eclip GUI
Cách đơn giản nhưng chưa hiệu quả vì Frame 1-2 đều chạy ra ngoài Tab Quản lý sinh viên
chúng ta có thể làm theo cách tiếp theo là [Cách 2]
JInternalFameTest.java - Internal Frame Class Test
Java 2016
/* JInternalFrameTest.java
* Copyright (c) 2014, HerongYang.com, All Rights Reserved.
*/
import java.awt.*;
import javax.swing.*;
public class JInternalFrameTest {
public static void main(String[] a) {
JFrame myFrame = new JFrame("Internal Frames");
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(300,300);
JDesktopPane myDesktop = new JDesktopPane();
myFrame.setContentPane(myDesktop);
JInternalFrame f = createFrame("Frame 1");
f.setLocation(10,10);
myDesktop.add(f);
f = createFrame("Frame 2");
f.setLocation(60,60);
myDesktop.add(f);
myFrame.setVisible(true);
}
private static JInternalFrame createFrame(String t) {
JInternalFrame f = new JInternalFrame(t);
f.setResizable(true);
f.setClosable(true);
f.setMaximizable(true);
f.setIconifiable(true);
f.setSize(200,200);
f.setVisible(true);
return f;
}
}
By: herongyang.com
Cách 2: Frame 1-2 không chạy ra ngoài mà luôn nằm trong Tab Quản lý sinh viên
Kết quả ta được như hình bên dưới
JInternalFame JDesktopPane TablePane Java Swing Eclip GUI
Menu tab & Cửa sổ mới Java Swing 2016
package demo;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JDesktopPane;
import java.awt.BorderLayout;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JLayeredPane;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.border.MatteBorder;
import javax.swing.JToolBar;
import javax.swing.JInternalFrame;
import java.awt.SystemColor;
public class Demo {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Demo window = new Demo();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Demo() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 554, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
JPanel panel = new JPanel();
tabbedPane.addTab("Quan ly sinh vien", null, panel, null);
tabbedPane.setForegroundAt(0, Color.BLACK);
tabbedPane.setMnemonicAt(0, 555);
tabbedPane.setDisabledIconAt(0, new ImageIcon("E:\\IMAGES\\GIF\\1174963_175991545922133_1335889537_n.jpg"));
tabbedPane.setBackgroundAt(0, SystemColor.menu);
panel.setLayout(null);
JDesktopPane desktopPane_1 = new JDesktopPane();
desktopPane_1.setDragMode(5);
desktopPane_1.setBackground(Color.LIGHT_GRAY);
desktopPane_1.setBounds(0, 0, 532, 234);
desktopPane_1.setToolTipText("");
desktopPane_1.setForeground(Color.GREEN);
panel.add(desktopPane_1);
JInternalFrame internalFrame = new JInternalFrame("Dang ky");
internalFrame.setClosable(true);
internalFrame.setIconifiable(true);
internalFrame.setMaximizable(true);
internalFrame.setEnabled(false);
internalFrame.setBounds(10, 35, 243, 171);
desktopPane_1.add(internalFrame);
JInternalFrame internalFrame_1 = new JInternalFrame("Lich hoc");
internalFrame_1.setClosable(true);
internalFrame_1.setMaximizable(true);
internalFrame_1.setIconifiable(true);
internalFrame_1.setBounds(276, 35, 246, 171);
desktopPane_1.add(internalFrame_1);
internalFrame_1.setVisible(true);
internalFrame.setVisible(true);
JPanel panel_1 = new JPanel();
tabbedPane.addTab("Quan ly diem", null, panel_1, null);
JPanel panel_2 = new JPanel();
tabbedPane.addTab("Quan ly mon hoc", null, panel_2, null);
JPanel panel_3 = new JPanel();
tabbedPane.addTab("Thong ke", null, panel_3, null);
}
}
0 nhận xét:
Post a Comment