I am working on an inventory management system with Java SE.I want the system to display a notification when the quantity of an item(s) in stock goes down below a set threshold. say ,when the quantity of an item in the database is below 50..The system should display a notification to the user. I have researched though,but the result don,t match up what exactly i need .
-
possible duplicate of [How to create a notification in swing](http://stackoverflow.com/questions/3240415/how-to-create-a-notification-in-swing) – GreatDane Jul 04 '14 at 12:43
-
How do you want the notification to be displayed? There are a lot of different possibilities here, and it would be helpful to know more. You should also consider when to check the database. Is it a single user application? Does the user have access to a display of the stock of all items? How do you add and subtract your stock in the database? Which (possibly all) of these parts of the possible problem is your specific problem? – jumps4fun Jul 04 '14 at 13:34
-
It's not clear where you're stuck: accessing the database? creating the notification? – trashgod Jul 04 '14 at 18:02
-
am ok with the notification now.but how to do the checking in the database.is it advisable i use a quartz,to run at certain time intervals and display the notification ? – codereal Jul 04 '14 at 19:00
2 Answers
If I correctly understood your question you looking for a possibility to inform user about an occured problem. Swing has 2 standard possibilities to do it: popup dialog messages (example here) and system tray messages.
Also you can use your own messaging service. For example you can implement a status bar for your application and and use it to show your messages. Here is a simple example how you can do it.

- 1
- 1

- 11,160
- 1
- 32
- 48
The approach you take to notify users of your application's state is highly dependent on the visual structure of your application and the platform it is running on. If your application is targetting a desktop environment and the message you're projecting isn't alerting the user to something critically important, then a little status bar may very well be a good choice.
If you're targetting an environment with limited on-screen real estate and need to ensure the user sees the message, then perhaps a dialog window overlaying the main application is for you. Below isa quick and dirty example of what a dialog overlaying the main application frame might look like.
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DialogExample extends JFrame
{
private final static String DIALOG_TITLE = "Warning Dialog";
private final static int DIALOG_ICON = JOptionPane.WARNING_MESSAGE;
private final JButton openPopupBtn;
public DialogExample()
{
this.openPopupBtn = new JButton("Open Dialog");
this.openPopupBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(DialogExample.this, "You just opened a dialog.", DIALOG_TITLE, DIALOG_ICON);
}
});
this.setTitle("Dialog Example");
this.setSize(640,480);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.add(this.openPopupBtn);
this.setResizable(false);
}
public static void main(String[] args) {
JFrame dialogExample = new DialogExample();
dialogExample.setVisible(true);
}
}
Should you like the second approach, the recommended reading would be How to Make Dialogs. This page shows the ability to add a little richness to these dialogs aswell.

- 2,223
- 1
- 21
- 37