【问题标题】:How to add frame to another frame?如何将框架添加到另一个框架?
【发布时间】:2015-01-31 19:20:54
【问题描述】:

在这里,我将使用DimensionToolkit 类在系统托盘中显示类似框架的弹出窗口。 我有 5 个弹出窗口。平均 5 帧显示一比一。之后,我想在单帧中显示所有帧,我可以在其中滚动该帧。

那么您能建议我如何实现吗?

int n=0;
while (itr.hasNext()) {
Object element = itr.next();

bean = (JavaBean) element;
System.out.print("---->" + bean.getTime());
System.out.print("---->" + bean.getTitle());
System.out.println("----->" + bean.getUrl());


final URI uri = new URI(bean.getUrl());
final JFrame frame = new JFrame();
frame.setSize(350, 70);
frame.add(new JSeparator(SwingConstants.HORIZONTAL));
frame.setAlwaysOnTop(true);
frame.setUndecorated(true);
frame.setLayout(new GridBagLayout());

JButton cloesButton = new JButton("X");
JButton linkbutton = new JButton("links");
addComponent(frame, linkbutton, 0, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
addComponent(frame, cloesButton, 1, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
linkbutton.setText("<HTML><div style='width:200px; color:#000; border:1px solid #e5e5e5; margin-right:5px;'>" + bean.getTitle() + "</div>" + "</HTML>");
linkbutton.setBackground(Color.LIGHT_GRAY);
linkbutton.setHorizontalAlignment(SwingConstants.LEFT);

cloesButton.setFocusable(false);
linkbutton.setToolTipText(uri.toString());

frame.add(linkbutton);
frame.add(cloesButton);
frame.setVisible(true);

//Set Pop up at bottom - right
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen
Insets toolHeight = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());// height of the task bar
//frame.setLocation(scrSize.width - frame.getWidth(), scrSize.height - toolHeight.bottom - frame.getHeight());
frame.setLocation(scrSize.width - frame.getWidth(), scrSize.height - toolHeight.bottom - (frame.getHeight() * (n + 1)));

n++;
}

【问题讨论】:

  • 为什么使用 5 帧?为什么不只有 1 个?
  • 它在循环中......在这里我得到一个超过一帧。
  • 请看那张图片,我发布的内容!!!!。这里是 3 帧...我想在单帧中显示所有 3 帧....@MadProgrammer

标签: java swing jframe


【解决方案1】:

在循环中定义 JPanel 而不是 Frame,并将所有 JPanel 添加到单个 Frame。

编辑:

类似这样的:

JFrame frame = ...
while(...) {
    JPanel panel = new JPanel();
    panel.add(buttons, etc)
    frame.add(panel);
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-10-31
  • 2018-05-26
  • 2014-01-31
  • 1970-01-01
  • 2017-11-26
  • 2021-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多