2014-12-03 141 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