Java JScrollPane-多个组件 [英] Java JScrollPane- Multiple components

查看:90
本文介绍了Java JScrollPane-多个组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在JScrollPane中添加2个图像。第一个图像是背景,第二个图像与第一个图像重叠。当我运行程序时问题只显示第二张图片!

I'm trying to add 2 images inside the JScrollPane. the first image is a background and the second one overlap the first one. The problem shows only the second image when i run my program!

请帮助

ImageIcon ii = new ImageIcon("mini_map.png");
JLabel label1=new JLabel(ii);

Icon icon = new ImageIcon("Mg.gif");
JLabel label2 = new JLabel(icon);

JScrollPane jsp=new JScrollPane();

jsp.getViewport().add(label1);
jsp.getViewport().add(label2 );


推荐答案

JViewport是一个单子容器,你可以'添加两个组件。

JViewport is a single-child container, you can't add two components.

要在任何容器中实现重叠(即z方向的堆栈组件),您主要是自己构建的,内置的 - 支持很差。要么必须在LayeredPane中管理它们(如前所述)或尝试OverlapLayout

To achieve an overlap (that is stack components in z-direction) in any container, you'r mostly on your own, the built-in support is poor. Either have to manage them in LayeredPane (as mentioned already) or try OverlapLayout

这篇关于Java JScrollPane-多个组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆