예제 #1
0
    def run(self):
        frame = JFrame('AbsoluteLayout',
                       defaultCloseOperation=JFrame.EXIT_ON_CLOSE)

        # Replace the default Layout Manager
        frame.setLayout(None)

        # Information defining button title, location & size
        data = [['A', 20, 10, 0, 0], ['B', 40, 40, 10, 10],
                ['C', 80, 20, 20, 20]]

        # For each data entry, create & position a button
        insets = frame.getInsets()
        for item in data:
            button = frame.add(JButton(item[0]))
            size = button.getPreferredSize()
            button.setBounds(insets.left + item[1], insets.top + item[2],
                             size.width + item[3], size.height + item[4])

        # Define the application frame size
        frame.setSize(
            300 + insets.left + insets.right,  # frame width
            150 + insets.top + insets.bottom  # frame height
        )

        # Make the frame visible
        frame.setVisible(1)