2014-12-03 180 views
0

这里我将使用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++; 
} 

enter image description here

+0

为什么用5帧?为什么不只是1? – MadProgrammer 2014-12-03 09:40:34

+0

它在循环中...在这里我得到一个帧。 – 2014-12-03 09:49:28

+0

请看看那个图片,我发布了!!!!。这里是3帧...我想在单帧中显示所有3帧.... @ MadProgrammer – 2014-12-03 09:54:20

回答

0

定义的JPanel,而不是框架进入循环,所有的JPanel的添加到一个单一的框架。

编辑:

事情是这样的:

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

itz意味着,而不是Jrame,我必须把JPanel ..... @ Paco – 2014-12-03 10:23:30

+0

我编辑我的答案给你看一个例子。 – 2014-12-03 10:25:59

+0

所以你可以告诉我在哪些地方我必须编辑...你可以编辑这段代码... – 2014-12-03 10:26:53