Created
October 15, 2013 08:51
-
-
Save mountcedar/6988648 to your computer and use it in GitHub Desktop.
Javaにおけるフレームの位置調整 ref: http://qiita.com/mountcedar/items/9b9366f463aa559400da
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import javax.swing.*; | |
import javax.swing.border.*; | |
import java.awt.event.*; | |
public class TestWindow extends JFrame { | |
public JTextArea textarea = null; | |
protected JLabel label = null; | |
public JTextField text = null; | |
public TestWindow () { | |
// ここからは全部UIのサンプルなので、意味は無い | |
this.setSize(480, 320); | |
this.setTitle("status"); | |
JPanel panel = new JPanel(); | |
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); | |
JPanel panel1 = new JPanel(); | |
panel1.setBorder(new EmptyBorder(5,5,5,5)); | |
label = new JLabel ("Hoge"); | |
panel1.add(label); | |
text = new JTextField ("None", 40); | |
panel1.add(text); | |
panel.add(panel1); | |
JPanel textAreaPanel = new JPanel(); | |
textAreaPanel.setBorder(new EmptyBorder(5,5,5,5)); | |
textarea = new JTextArea(20, 50); | |
JScrollPane scrollPane = new JScrollPane(textarea); | |
scrollPane.setSize(450,300); | |
textAreaPanel.add(scrollPane); | |
panel.add(textAreaPanel); | |
this.setContentPane(panel); | |
this.pack(); | |
// ここまでは全部UIのサンプルなので、意味は無い | |
// setLocation()はpockの後に書くこと。 | |
// ここからが該当のコード | |
Toolkit toolkit = Toolkit.getDefaultToolkit(); | |
Dimension screenSize = toolkit.getScreenSize(); | |
this.setLocation(100, (screenSize.height - this.getHeight()) / 2); | |
this.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment