退房太阳对mixing heavy and light components文章 - 因为JDICPlus基本上IE嵌入到你的应用程序,这是一个重量级的组件。
您可以通过使用其他重量级组件(例如AWT Button)将按钮放在浏览器窗口上,或者将按钮放置到放置在浏览器上的JPopupMenu上,并使用setDefaultLightWeightPopupEnabled(false)对其进行设置它重量级。
编辑
我使用的JPopupMenu在重量级的组件来显示一个JButton写了一个例子 - JPopupMenu的作品,但它确实有内置的行为关闭菜单时,在弹出的失去焦点的弹出窗口或组件。我向重量级组件添加了一个MouseMotionListener,以在鼠标进入按钮应该位置附近的边界框时显示弹出窗口。不知道这是否适合你,因为按钮并不总是显示。
包括代码示例和截图 -
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;
public class LightHeavy extends JFrame {
private Component heavyweightComponent;
private JPopupMenu backButton, forwardButton;
public LightHeavy() {
super("LightHeavy");
heavyweightComponent = buildHeavyweightComponent();
heavyweightComponent.setBackground(Color.ORANGE);
heavyweightComponent.setSize(640, 480);
getContentPane().add(heavyweightComponent, BorderLayout.CENTER);
ImageIcon backArrow = new ImageIcon("left_arrow_128.png");
backButton = buildPopup(backArrow);
ImageIcon forwardArrow = new ImageIcon("right_arrow_128.png");
forwardButton = buildPopup(forwardArrow);
heavyweightComponent.addMouseMotionListener(new MouseInputAdapter() {
public void mouseMoved(MouseEvent e) {
Rectangle backHotSpot = new Rectangle(0, 0, 200, 200);
Rectangle forwardHotSpot = new Rectangle(heavyweightComponent.getWidth() - 200, 0, 200, 200);
if (backHotSpot.contains(e.getPoint())) {
backButton.show(heavyweightComponent, 0, 0);
} else if (forwardHotSpot.contains(e.getPoint())) {
forwardButton.show(heavyweightComponent,
heavyweightComponent.getWidth() - forwardButton.getWidth(), 0);
}
}
});
}
private Component buildHeavyweightComponent() {
return new Canvas() {
public void paint(Graphics og) {
super.paint(og);
Graphics2D g = (Graphics2D)og;
String big = "Heavyweight Component";
g.setFont(getFont().deriveFont(20F));
Rectangle2D bigBounds = g.getFontMetrics().getStringBounds(big, g);
g.drawString(big,
(this.getWidth() - (int)bigBounds.getWidth())/2,
(this.getHeight() - (int)bigBounds.getHeight())/2);
String little = "(assume this is JDICplus)";
g.setFont(getFont().deriveFont(10F));
Rectangle2D littleBounds = g.getFontMetrics().getStringBounds(little, g);
g.drawString(little,
(this.getWidth() - (int)littleBounds.getWidth())/2,
(this.getHeight() + (int)littleBounds.getHeight())/2);
}
};
}
private JPopupMenu buildPopup(Icon icon) {
JButton button = new JButton(icon);
JPopupMenu popup = new JPopupMenu();
popup.add(button);
popup.setBorderPainted(false);
popup.setLightWeightPopupEnabled(false);
return popup;
}
public static void main(String[] args) {
JFrame f = new LightHeavy();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
这里的左侧显示与JButton的截图 - 注意,您也将无法做任何很酷的透明效果,为你处理与重量级组件。
screenshot of code http://i30.tinypic.com/2zsbdsl.png
鉴于我的Java的经验,如果你需要,我认为你会更好看Windows特定的解决方案,Windows特定的技术。可悲的是,我不能提出任何更具体的建议。 – Mark 2009-07-15 21:54:06