【问题标题】:L shaped java application windowL形java应用程序窗口
【发布时间】:2009-10-22 17:58:45
【问题描述】:

我想创建一个“L”形的 java 应用程序,以便该应用程序只占据屏幕的左边框和下边框。我也不希望顶部有正常的边框和标题栏。我见过其他人创建圆形和其他类似的形状,但没有复杂的形状。这是用于 windows xp 计算机的,永远不会在任何其他操作系统上。

那么,我该怎么做呢?

【问题讨论】:

    标签: java windows shaped-window


    【解决方案1】:

    java.awt.Window/javax.swing.JWindowjava.awt.Frame/javax.swing.JFramesetUndecorated 将创建无框窗口。您可以将两个或更多组合在一起形成一个 L 形。

    从 6u10 开始,Sun JRE 还具有非标准 API 或非矩形和透明窗口。

    【讨论】:

      【解决方案2】:

      我认为这应该是可能的,尽管您可能必须小心布置组件。如果您查看here,并阅读关于设置窗口形状的部分,它会说“形状可以是 java.awt.Shape 接口的任何实例”。如果您再查看 Shape 接口,java.awt.Polygon 实现了该接口。所以你应该能够实现一个带有“L”形的多边形。试一试。

      【讨论】:

        【解决方案3】:

        Asa 来了,这正是你需要的:

        import com.sun.awt.AWTUtilities;
        import java.awt.Polygon;
        import java.awt.Shape;
        import java.awt.event.ComponentAdapter;
        import java.awt.event.ComponentEvent;
        import javax.swing.JFrame;
        
        public static void main(String[] args)
        {
            // create an undecorated frame
            final JFrame lframe = new JFrame();                
            lframe.setSize(1600, 1200);
            lframe.setUndecorated(true);
        
            // using component resize allows for precise control
            lframe.addComponentListener(new ComponentAdapter() {
                // polygon points non-inclusive
                // {0,0} {350,0} {350,960} {1600,960} {1600,1200} {0,1200}
                int[] xpoints = {0,350,350,1600,1600,0};
                int[] ypoints = {0,0,960,960,1200,1200};
        
                @Override
                public void componentResized(ComponentEvent evt)
                {  
                    // create the polygon (L-Shape)
                    Shape shape = new Polygon(xpoints, ypoints, xpoints.length);
        
                    // set the window shape
                    AWTUtilities.setWindowShape(lframe, shape);
                }
            });
        
            // voila!
            lframe.setVisible(true);
        }
        

        reference -> "Setting the Shape of a Window"

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-01-06
          • 1970-01-01
          • 1970-01-01
          • 2016-10-11
          • 2020-03-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多