Java GUI application help needed
Java GUI application help needed
Hi guys!
I have a Java SE desktop application that I need a bit of help with... The application has a main form (jFrame) that is shown when you run the jar file. On this main form, there are a few buttons that open other windows (also jFrames) that perform specific tasks.
So, for example, the main form might have a button that opens a window to add users on and another button to open a window to edit user information on. (These "secondary" jFrames might open other jFrames)
The problem that I have is that each of these jFrames have their own taskbar item, which causes the taskbar to fill up quite a bit just for this one application. I just want one taskbar item for any ammount of jFrames that might be open.
I know that I can make use of a jFrame with a DesktopPane and then add jInternalFrames to the DesktopPane container, but some of the jFrames that I open from the main jFrame then have to open maybe even more jFrames, and then this becomes a little bit confusing.
Any help/sample code would be much appreciated. BTW, I am using Netbeans 6.5 to develop this app.
Thanks!
I have a Java SE desktop application that I need a bit of help with... The application has a main form (jFrame) that is shown when you run the jar file. On this main form, there are a few buttons that open other windows (also jFrames) that perform specific tasks.
So, for example, the main form might have a button that opens a window to add users on and another button to open a window to edit user information on. (These "secondary" jFrames might open other jFrames)
The problem that I have is that each of these jFrames have their own taskbar item, which causes the taskbar to fill up quite a bit just for this one application. I just want one taskbar item for any ammount of jFrames that might be open.
I know that I can make use of a jFrame with a DesktopPane and then add jInternalFrames to the DesktopPane container, but some of the jFrames that I open from the main jFrame then have to open maybe even more jFrames, and then this becomes a little bit confusing.
Any help/sample code would be much appreciated. BTW, I am using Netbeans 6.5 to develop this app.
Thanks!
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
Re: Java GUI application help needed
Use JDialog and make it modles and you are propably using JWindow to create the windows not JFrame as JFrame is a component which you can add to a JWindow. a JFrame itself will not show on the taskbar. But to resolve your problem use JDialog. The only other option would be JNDI which is a tad tricky and not always a wise choice as it becomes platform dependant.
- Spoiler (show)
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
Re: Java GUI application help needed
JWindow with custom widgets will not appear in the taskbar...
DesktopPane/JInternalFrame is the way to go, but it sounds like your design may need some work... how many frames are you opening?
DesktopPane/JInternalFrame is the way to go, but it sounds like your design may need some work... how many frames are you opening?
Most people would sooner die than think; in fact, they do so - Bertrand Russel
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
Re: Java GUI application help needed
The puppy is propably one up on me in terms of Java I have not worked with it for some thime thoug.
*Whips out manuals*
*Whips out manuals*
- Spoiler (show)
Re: Java GUI application help needed
Thanks! The jDialog does the trick. I didnt really try it as most of the articles that I read only made use of jDialogs as input type of forms where the user can input information on, and not windows which can act as "main" ones themselves.
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
Re: Java GUI application help needed
that would be because JDialog, as a container component, stinks around any decently threaded app... a modal dialog is even worse... i would strongly advise you use a properly threaded container, (JWindow), before using dialogs...PypLaCe wrote:most of the articles that I read only made use of jDialogs as input type of forms where the user can input information on, and not windows which can act as "main" ones themselves.
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Re: Java GUI application help needed
@ rusty's earlier post
The application might have a process flow as follows:
On main screen, press button which displays search screen. On search screen, enter search key/text and hit button which displays search results screen and the results in jTable. On search results screen, select row in jTable and press button to show complete information on another screen.
This is just one of many that the app could have.
All these screens are jFrames at the moment.
The application might have a process flow as follows:
On main screen, press button which displays search screen. On search screen, enter search key/text and hit button which displays search results screen and the results in jTable. On search results screen, select row in jTable and press button to show complete information on another screen.
This is just one of many that the app could have.
All these screens are jFrames at the moment.
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
Re: Java GUI application help needed
Events -- OOoh why people underestemate events I would never know
PypLaCe - events are your friends. Create your own event and pass the information you want or need displayed back with it. Then open up a new window and display the details. No need to have this huge chain of windows open. And I would have to agree with rusty regarding threads and JDialog. If you can avoid them like the plaige when using threads.
For event read this
PypLaCe - events are your friends. Create your own event and pass the information you want or need displayed back with it. Then open up a new window and display the details. No need to have this huge chain of windows open. And I would have to agree with rusty regarding threads and JDialog. If you can avoid them like the plaige when using threads.
For event read this
- Spoiler (show)
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
Re: Java GUI application help needed
Any case I am quickly gonna grab the latest netbeans and have a look. I got some spare bw
- Spoiler (show)
Re: Java GUI application help needed
Im quite impressed with the latest netbeans... A lot better than what it was just a few year back.
Anyway, back to your previouse post RuadRauFlessa. That article on events that you linked to, isnt a bit overkill for what I want to do? I mean, I'm opening a few simple windows that display some info based on actions that took place in the previouse window. (Unless I'm not getting the picture you are trying to paint... )
Anyway, back to your previouse post RuadRauFlessa. That article on events that you linked to, isnt a bit overkill for what I want to do? I mean, I'm opening a few simple windows that display some info based on actions that took place in the previouse window. (Unless I'm not getting the picture you are trying to paint... )
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
Re: Java GUI application help needed
Well look at it this way
Main Screen -> Search Screen -> Search Display Screen -> Data Display Screen
See that as your flow of processes. Now by the time you (with your design) get to displaying the data to the user you will have 4 screens open. Instead cosnider the following
Main Screen -> Search Screen
-> Search Display Screen
-> Data Display Screen
Open the Search Screen and when it closes, using events, pass the search criteria back. Then open the Search Display Screen and pass it the search criteria which the search display screen will then use to retrieve the diffirent matches for the criteria. Then do the same for the Data Display Screen. Have the Search Display Screen only return the ID of the selected option (I assume the data you are searching for is indexed in a DB). Open the Data Display Screen and look up the data and display it. This is the most robust way you can handle screens. Yes you will have a bunch of callbacks in your main window but part of the idea is to complete abstraction.
You could always build all three screens into one but then you are going to rewrite a lot of code. with the above you only really need one search screen and then in the screen cater for any type of data you will need to search for. in the Search Display Screen you could make it dynamic enouth to be able to display search results for anything you are able to enter search criterion for in the Search Screen. The Data Display Screen you can do with what you want as you won't always want it dynamically generated. You could even set up some nice xml files to hold the defenitions for the diff screens or if you have a db store an entry for each thing you want to be able to search for.
The last version of NetBeans I worked on was 5.5. I have always been a fan of NetBeans. It used to be murder on resources but which IDE is not.
Main Screen -> Search Screen -> Search Display Screen -> Data Display Screen
See that as your flow of processes. Now by the time you (with your design) get to displaying the data to the user you will have 4 screens open. Instead cosnider the following
Main Screen -> Search Screen
-> Search Display Screen
-> Data Display Screen
Open the Search Screen and when it closes, using events, pass the search criteria back. Then open the Search Display Screen and pass it the search criteria which the search display screen will then use to retrieve the diffirent matches for the criteria. Then do the same for the Data Display Screen. Have the Search Display Screen only return the ID of the selected option (I assume the data you are searching for is indexed in a DB). Open the Data Display Screen and look up the data and display it. This is the most robust way you can handle screens. Yes you will have a bunch of callbacks in your main window but part of the idea is to complete abstraction.
You could always build all three screens into one but then you are going to rewrite a lot of code. with the above you only really need one search screen and then in the screen cater for any type of data you will need to search for. in the Search Display Screen you could make it dynamic enouth to be able to display search results for anything you are able to enter search criterion for in the Search Screen. The Data Display Screen you can do with what you want as you won't always want it dynamically generated. You could even set up some nice xml files to hold the defenitions for the diff screens or if you have a db store an entry for each thing you want to be able to search for.
The last version of NetBeans I worked on was 5.5. I have always been a fan of NetBeans. It used to be murder on resources but which IDE is not.
- Spoiler (show)
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
Re: Java GUI application help needed
ahh...PypLaCe wrote:press button which displays search screen. On search screen, enter search key/text and hit button which displays search results screen and the results in jTable. On search results screen, select row in jTable and press button to show complete information on another screen.
is there any reason the above transaction couldn't happen in one JInternalFrame... the "search" screen is effectively just requesting a single input field - no need to open multiple windows for each step in the operation...
JTable's MVC design means you can instantiate and use it before populating it with data - once you do populate it, the table will automatically alert any listeners, (table/scrollpane/viewport), to this fact and they, in turn, will automatically adjust layouts, cell renderers, etc to reflect the underlying change to the data...
the process, as you decribe it, would probably require that you would have an input panel to initiate the search process, a selectable tree panel to pick the relevant record and another panel to display the desired data, all of which could live, quite happily, within the same window...
<edit>
sorry - really busy at the moment.. will try and post some examples later..
to get you started:
Code: Select all
public class MyDataModel extends DefaultTableModel {
private Vector<Vector<Object>> buf;
private String[] headers = {"my","column","header","labels"};
public MyDataModel(){
//init
}
//NB method
public void setData(Vector<Vector<Object>> data){
buf = data;
this.fireTableDataChanged();//notify all listeners!
}
public int getColumnCount(){
return headers.length;
}
public int getRowCount(){
if(buf!=null)
return buf.size();
return 0;
}
public String getColumnName(int col){
return headers[col];
}
//example of how you can force a renderer type
public Class getColumnClass(int col){
switch(col){
case 2:{return Boolean.class;} //will ensure a checkbox is used
default:{return String.class;}
}
}
public Object getValueAt(int row, int col){
if(buf!=null)
return buf.get(row).get(col);
}
}
Code: Select all
public static void main(String[] args){
javax.swing.JFrame frm = new javax.swing.JFrame("Table Model Test");
frm.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
final MyDataModel mod = new MyDataModel();
frm.add(new JScrollPane(new JTable(mod)));
frm.setSize(640, 480);
frm.setLocationRelativeTo(null);
frm.setVisible(false);
java.util.Timer tim = new java.util.Timer("TicTest");
java.util.TimerTask tst = new java.util.TimerTask(){
public void run(){
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
Vector<Object> row1 = new Vector<Object>();
Vector<Object> row2 = new Vector<Object>();
Vector<Object> row3 = new Vector<Object>();
row1.add("some");
row1.add("info");
row1.add(false);
row1.add("here");
row2.add("more");
row2.add("data");
row2.add(true);
row2.add("there");
row3.add("final");
row3.add("row");
row3.add(false);
row3.add("here");
data.add(row1);
data.add(row2);
data.add(row3);
mod.setData(data);//update the model
}
};
tim.schedule(tst, 120000);
}
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Re: Java GUI application help needed
(Sorry, havent refreshed the page in a while a didnt see your latest post... Reading it now)
There is no particular reason that they are on different windows other than that it separates the code...
So, by you saying that jDesktopPane/jInternal frame is the way to go, I assume that I should have the variouse windows merged into one jInternalFrame with variouse jPanels for each task? If that is the case (here is the noob question), how would i move between the variouse panels in the internal frame?
There is no particular reason that they are on different windows other than that it separates the code...
So, by you saying that jDesktopPane/jInternal frame is the way to go, I assume that I should have the variouse windows merged into one jInternalFrame with variouse jPanels for each task? If that is the case (here is the noob question), how would i move between the variouse panels in the internal frame?
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
Re: Java GUI application help needed
Code: Select all
JFrame.remove([component]);
JFrame.add([component]);
- Spoiler (show)
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
Re: Java GUI application help needed
ok... long post coming... expect it to be nasty...
If your package tree changes in any way, be sure to correct this in the class headers!
Package tree
=========
[src]
==============
DataSource.java (dummy class used to spit out random information)
==============
DeferredTask.java (Interface representing threaded tasks)
==============
ActionToggle.java (Event listener used to process UI actions and generate cache tasks)
==============
DesktopExample.java (Main dekstop UI, showing how to manage menus, internal frames, etc)
If your package tree changes in any way, be sure to correct this in the class headers!
Package tree
=========
[src]
- -simpledesktop
- -factories
- -DataSource.java
- -DeferredTask.java
-DeferredTaskEvent.java
-DeferredTaskListener.java
-TableCacheTask.java
-TreeCacheTask.java
- -ActionToggle.java
-CustomTableModel.java
-CustomTreeModel.java
-ProcessPanel.java
-SearchPane.java
- -factories
==============
DataSource.java (dummy class used to spit out random information)
- Spoiler (show)
==============
DeferredTask.java (Interface representing threaded tasks)
- Spoiler (show)
- Spoiler (show)
- Spoiler (show)
- Spoiler (show)
- Spoiler (show)
==============
ActionToggle.java (Event listener used to process UI actions and generate cache tasks)
- Spoiler (show)
- Spoiler (show)
- Spoiler (show)
- Spoiler (show)
- Spoiler (show)
==============
DesktopExample.java (Main dekstop UI, showing how to manage menus, internal frames, etc)
- Spoiler (show)
Last edited by rustypup on 15 Jan 2009, 10:48, edited 1 time in total.
Most people would sooner die than think; in fact, they do so - Bertrand Russel
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
Re: Java GUI application help needed
once you've got it to compile, we'll chat again..
<edit>
perfect spacing - see prior page...
</edit>
<edit>
perfect spacing - see prior page...
</edit>
Most people would sooner die than think; in fact, they do so - Bertrand Russel