==[[Swing レイアウト 2]]==
[[Swing]] |
====FlowLayout====
=====L to [[R]]=====
[[File:1198_flow01.jpg]]
=====[[R ]] to L=====
[[File:1199_flow02.jpg]]
====GridBagLayout====
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.[[JFrame]];
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.SwingUtilities[[Swing]]Utilities;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
@SuppressWarnings("serial")
public class LayoutTest2 extends [[JFrame ]] {
/**
* FlowLayout test
*/
public void testFlowLayout() {
[[JFrame ]] frame = new [[JFrame]]("FlowLayout Test");
Container pane = frame.getContentPane();
public void actionPerformed(ActionEvent e) {
ComponentOrientation co = null;
if ("L to [[R]]".equals(((JButton)e.getSource()).getText())) { co = ComponentOrientation.LEFT_TO_RIGHTLEFT_TO_[[R]]IGHT;
} else {
co = ComponentOrientation.RIGHT_TO_LEFT[[R]]IGHT_TO_LEFT;
}
panel1.setComponentOrientation(co);
}
JButton btn1 = new JButton("L to [[R]]");
btn1.addActionListener(new MyMethodLocalActionListener());
JButton btn2 = new JButton("[[R ]] to L");
btn2.addActionListener(new MyMethodLocalActionListener());
*/
public void testGridBagLayout() {
[[JFrame ]] frame = new [[JFrame]]("GridBagLayout Test");
Container pane = frame.getContentPane();
{0,2}/*7*/,{2,2}/*8*/,{4,2}/*9*/,
};
c.fill = GridBagConstraints.HORIZONTALHO[[R]]IZONTAL; // 共通設定
c.gridwidth = 6; // ↓ 列数設定
c.gridx = 0;
c.gridy = 0;
c.gridwidth = GridBagConstraints.REMAINDER[[R]]EMAINDE[[R]]; // ↑ 最終行 JTextField txtResult txt[[R]]esult = new JTextField(""); gbl.setConstraints(txtResulttxt[[R]]esult, c); pane.add(txtResulttxt[[R]]esult);
c.gridwidth = 3; // ↓ 列数設定
c.gridx = 3;
c.gridy = 1;
c.gridwidth = GridBagConstraints.REMAINDER[[R]]EMAINDE[[R]]; // ↑ 最終行
JButton btnC = new JButton("C");
gbl.setConstraints(btnC, c);
*/
public void testGridLayout() {
[[JFrame ]] frame = new [[JFrame]]("GridLayout Test");
final Container pane = frame.getContentPane();
pane.setLayout(new BorderLayout());
}
);
ctrlPanel.add(new JLabel("gap 0 - 50"), BorderLayout.NORTHNO[[R]]TH); ctrlPanel.add(slider, BorderLayout.CENTERCENTE[[R]]);
pane.add(ctrlPanel, BorderLayout.NORTHNO[[R]]TH); pane.add(gridPanel, BorderLayout.CENTERCENTE[[R]]);
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel[[Windows]]LookAndFeel");
// UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
SwingUtilities[[Swing]]Utilities.invokeLater( new Runnable[[R]]unnable() {
public void run() {
LayoutTest2 lt = new LayoutTest2();
lt.setDefaultCloseOperation([[JFrame]].EXIT_ON_CLOSE);
lt.setVisible(true);
}