Swing-jwindow
SWING-JWindowクラス
前書き
クラス JWindow は表示可能なコンテナですが、タイトルバーやウィンドウ管理ボタンはありません。
クラス宣言
以下は javax.swing.JWindow クラスの宣言です-
public class JWindow
extends Window
implements Accessible, RootPaneContainer
フィールド
以下は java.awt.Component クラスのフィールドです-
- protected AccessibleContext AccessibleContext -アクセス可能なコンテキストプロパティ。
- protected JRootPane rootPane -このフレームのcontentPaneおよびオプションのmenuBarを管理するJRootPaneインスタンス、およびglassPane。
- protected boolean rootPaneCheckingEnabled -trueの場合、addおよびsetLayoutの呼び出しはcontentPaneに転送されます。
クラスコンストラクター
Sr.No. | Constructor & Description |
---|---|
1 |
JWindow() 所有者を指定せずにウィンドウを作成します。 |
2 |
JWindow(Frame owner) 指定された所有者フレームでウィンドウを作成します。 |
3 |
JWindow(GraphicsConfiguration gc) 画面デバイスの指定されたGraphicsConfigurationでウィンドウを作成します。 |
4 |
JWindow(Window owner) 指定された所有者ウィンドウでウィンドウを作成します。 |
5 |
JWindow(Window owner, GraphicsConfiguration gc) 指定された所有者ウィンドウと画面デバイスのGraphicsConfigurationでウィンドウを作成します。 |
クラスメソッド
Sr.No. | Method & Description |
---|---|
1 |
protected void addImpl(Component comp, Object constraints, int index) 指定された子コンポーネントを追加します。 |
2 |
protected JRootPane createRootPane() コンストラクターメソッドによって呼び出され、デフォルトのrootPaneを作成します。 |
3 |
AccessibleContext getAccessibleContext() このJWindowに関連付けられたAccessibleContextを取得します。 |
4 |
Container getContentPane() このウィンドウのcontentPaneであるコンテナを返します。 |
5 |
Component getGlassPane() このウィンドウのglassPaneコンポーネントを返します。 |
6 |
Graphics getGraphics() このコンポーネントのグラフィックスコンテキストを作成します。 |
7 |
JLayeredPane getLayeredPane() このウィンドウのlayeredPaneオブジェクトを返します。 |
8 |
JRootPane getRootPane() このウィンドウのrootPaneオブジェクトを返します。 |
9 |
TransferHandler getTransferHandler() transferHandlerプロパティを取得します。 |
10 |
protected boolean isRootPaneCheckingEnabled() addおよびsetLayoutの呼び出しがcontentPaneに転送されるかどうかを返します。 |
11 |
protected String paramString() このJWindowの文字列表現を返します。 |
12 |
void remove(Component comp) 指定されたコンポーネントをコンテナから削除します。 |
13 |
void repaint(long time, int x, int y, int width, int height) timeミリ秒以内にこのコンポーネントの指定された長方形を再描画します。 |
14 |
void setContentPane(Container contentPane) このウィンドウのcontentPaneプロパティを設定します。 |
15 |
void setGlassPane(Component glassPane) glassPaneプロパティを設定します。 |
16 |
void setLayeredPane(JLayeredPane layeredPane) layeredPaneプロパティを設定します。 |
17 |
void setLayout(LayoutManager manager) LayoutManagerを設定します。 |
18 |
protected void setRootPane(JRootPane root) このウィンドウの新しいrootPaneオブジェクトを設定します。 |
19 |
protected void setRootPaneCheckingEnabled(boolean enabled) addおよびsetLayoutの呼び出しをcontentPaneに転送するかどうかを設定します。 |
20 |
void setTransferHandler(TransferHandler newHandler) transferHandlerプロパティを設定します。これは、このコンポーネントへのデータの転送をサポートするメカニズムです。 |
21 |
void update(Graphics g) paint(g)を呼び出します。 |
22 |
protected void windowInit() JWindowを適切に初期化するためにコンストラクターによって呼び出されます。 |
継承されるメソッド
このクラスは、次のクラスからメソッドを継承します-
- java.awt.Window
- java.awt.Container
- java.awt.Component
- java.lang.Object
JWindowの例
たとえば、 D:/> SWING> com> finddevguides> gui> の任意のエディターを使用して、次のJavaプログラムを作成します。
SwingContainerDemo.java
package com.finddevguides.gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingContainerDemo {
private JFrame mainFrame;
private JLabel headerLabel;
private JLabel statusLabel;
private JPanel controlPanel;
private JLabel msglabel;
public SwingContainerDemo(){
prepareGUI();
}
public static void main(String[] args){
SwingContainerDemo swingContainerDemo = new SwingContainerDemo();
swingContainerDemo.showJWindowDemo();
}
private void prepareGUI(){
mainFrame = new JFrame("Java Swing Examples");
mainFrame.setSize(400,400);
mainFrame.setLayout(new GridLayout(3, 1));
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
headerLabel = new JLabel("", JLabel.CENTER);
statusLabel = new JLabel("",JLabel.CENTER);
statusLabel.setSize(350,100);
msglabel = new JLabel("Welcome to finddevguides SWING Tutorial.", JLabel.CENTER);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
}
private void showJWindowDemo(){
headerLabel.setText("Container in action: JWindow");
final MessageWindow window = new MessageWindow(
mainFrame, "Welcome to finddevguides SWING Tutorial.");
JButton okButton = new JButton("Open a Window");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
window.setVisible(true);
statusLabel.setText("A Window shown to the user.");
}
});
controlPanel.add(okButton);
mainFrame.setVisible(true);
}
class MessageWindow extends JWindow{
private String message;
public MessageWindow(JFrame parent, String message) {
super(parent);
this.message = message;
setSize(300, 300);
setLocationRelativeTo(parent);
}
public void paint(Graphics g) {
super.paint(g);
g.drawRect(0,0,getSize().width - 1,getSize().height - 1);
g.drawString(message,50,150);
}
}
}
コマンドプロンプトを使用してプログラムをコンパイルします。 D:/> SWING に移動して、次のコマンドを入力します。
D:\SWING>javac com\finddevguides\gui\SwingContainerDemo.java
エラーが発生しない場合、コンパイルが成功したことを意味します。 次のコマンドを使用してプログラムを実行します。
D:\SWING>java com.finddevguides.gui.SwingContainerDemo
次の出力を確認します。