栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何移动放置在容器底部的最小化组件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何移动放置在容器底部的最小化组件?

我已经在

metal
Windows L&F
上进行了测试,您可能需要与
其他一些测试。

基本上,当组件失效并 调用该doLayout方法时
,我们将检查是否存在任何

JInternalframe.JDesktopIcon

组件。然后,我们将它们取出并按照自己的意愿进行布局…

public class TestInternalframe {    public static void main(String[] args) {        new TestInternalframe();    }    private int xpos = 0;    private int ypos = 0;    public TestInternalframe() {        EventQueue.invokeLater(new Runnable() { @Override public void run() {     try {         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());     } catch (Exception exp) {         exp.printStackTrace();     }     DesktopPane pane = new DesktopPane();     pane.add(newInternalframe());     pane.add(newInternalframe());     pane.add(newInternalframe());     Jframe frame = new Jframe();     frame.add(pane);     frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);     frame.setSize(400, 400);     frame.setLocationRelativeTo(null);     frame.setVisible(true); }        });    }    public JInternalframe newInternalframe() {        JInternalframe inf = new JInternalframe("Blah", true, true, true, true);        inf.setLocation(xpos, ypos);        inf.setSize(100, 100);        inf.setVisible(true);        xpos += 50;        ypos += 50;        return inf;    }    public class DesktopPane extends JDesktopPane {        @Override        public void doLayout() { super.doLayout(); List<Component> icons = new ArrayList<Component>(25); for (Component comp : getComponents()) {     if (comp instanceof JInternalframe.JDesktopIcon) {         icons.add(comp);     } } int x = 0; for (Component icon : icons) {     int y = getHeight() - icon.getHeight();     icon.setLocation(x, y);     x += icon.getWidth(); }        }    }}

Make no mistake, this is a rough hack

Updated

int x = 0;for (Component icon : icons) {    int y = getHeight() - icon.getHeight();    icon.setLocation(x, y);    x += icon.getWidth();    setLayer(icon, 10); // <--- Add me}

对于另一个问题,您只需要将图标移到更高的层即可。在
这个问题中,你确实需要找到一个层足够高的。您可以
使用Integer.MAX_VALUE,但这有点苛刻(并且您可能想要
在其顶部放置一些东西),相反,您可以计算最大
层数,并在其上放置+1…

public void doLayout() {    super.doLayout();    List<Component> icons = new ArrayList<Component>(25);    int maxLayer = 0;    for (Component comp : getComponents()) {        if (comp instanceof JInternalframe.JDesktopIcon) { icons.add(comp); maxLayer = Math.max(getLayer(comp), maxLayer);        }    }    maxLayer++;    int x = 0;    for (Component icon : icons) {        int y = getHeight() - icon.getHeight();        icon.setLocation(x, y);        x += icon.getWidth();        setLayer(icon, maxLayer);    }}

您真的需要花时间研究如何使用内部
框架
和如何使用分层
窗格,
因为(至少最后一部分)涵盖了这些……



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/455150.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号