0

Here I am to show popup like frame in system tray using Dimension and Toolkit class. I have 5 pop ups. Mean 5 frames are showing one over one. After that I want to show all frames in single frame, where I can scroll this frame.

So can you please suggest to me how to achieve that?

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

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
md razi
  • 67
  • 4
  • 12

1 Answers1

0

Define JPanel instead of Frame into the loop and add all of the JPanel to one single Frame.

EDIT:

Something like this:

JFrame frame = ...
while(...) {
    JPanel panel = new JPanel();
    panel.add(buttons, etc)
    frame.add(panel);
}
Paco Abato
  • 3,920
  • 4
  • 31
  • 54
  • So can you please tell in which places i have to edit...can u please edit this code... – md razi Dec 03 '14 at 10:26
  • That's your work ;) Read Oracle's Swing tutorial, for example: https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html#contentpane – Paco Abato Dec 03 '14 at 10:34
  • what about Jscroll ?i want to maintain like this mean in jscrollPanel, i have to add frame... – md razi Dec 03 '14 at 10:38
  • Add a ScrooPane to your JFrame. Maybe this http://stackoverflow.com/questions/16505239/add-a-jscrollpane-to-a-jframe and http://stackoverflow.com/questions/18481241/how-to-add-jscrollpane-to-jframe will help you. – Paco Abato Dec 03 '14 at 10:46