Results 1 to 20 of 22
Thread: Running a JPanel
- 09-27-2010, 02:42 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
Running a JPanel
Hello,
Actually I have a class MainPanel that implements a Jpanel..... and a class WindAnalysis with the main method....
I am calling an object of that class in a main metho, But nothing appears on screen... No panel etc....
The code of main class is:
public class WindAnalysis extends JPanel {
/**
* @param args
*/
public static void main(String[] args) {
// Auto-generated method stub
MainPanel mainPanel = new MainPanel();
}
}
whereas the class MainPanel is as follows:
public class MainPanel extends JPanel {
private static JTabbedPane tabbedPane = null;
public static final int WIDTH = 800;
public static final int HEIGHT = 600;
public static MainPanel instance = null;
public OptionPanel optionPanel = null;
public ChartPanel chartOnePanel[] = null; //chart one panel for wind 1 and 2
public ChartPanel chartTwoPanel[] = null;
public ChartPanel chartThreePanel[] = null;
public ChartPanel chartFourPanel[] = null;
public UserData userData = null;
public MainPanel() {
instance = this;
setLayout(new BorderLayout());
tabbedPane = new JTabbedPane();
JTabbedPane windOnePane = new JTabbedPane();
JTabbedPane windTwoPane = new JTabbedPane();
userData = new UserData();
chartOnePanel = new ChartPanel[2];
chartTwoPanel = new ChartPanel[2];
chartThreePanel = new ChartPanel[2];
chartFourPanel = new ChartPanel[2];
chartOnePanel[0] = new ChartPanel("Wind1chart1");
chartOnePanel[1] = new ChartPanel("Wind2chart1");
chartTwoPanel[0] = new ChartPanel("Wind1chart2");
chartTwoPanel[1] = new ChartPanel("Wind2chart2");
chartThreePanel[0] = new ChartPanel("Wind1chart3");
chartThreePanel[1] = new ChartPanel("Wind2chart3");
chartFourPanel[0] = new ChartPanel("Wind1chart4");
chartFourPanel[1] = new ChartPanel("Wind2chart4");
windOnePane.addTab("Frequency distribution",chartOnePanel[0]);
windOnePane.addTab("Diurnal distribution",chartTwoPanel[0]);
windOnePane.addTab("Prevalent wind direction",chartThreePanel[0]);
windOnePane.addTab("Avg wind speed direction",chartFourPanel[0]);
windTwoPane.addTab("Frequency distribution",chartOnePanel[1]);
windTwoPane.addTab("Diurnal distribution",chartTwoPanel[1]);
windTwoPane.addTab("Prevalent wind direction",chartThreePanel[1]);
windTwoPane.addTab("Avg wind speed direction",chartFourPanel[1]);
optionPanel = new OptionPanel();
tabbedPane.setBorder(BorderFactory.createCompoundB order(BorderFactory
.createEmptyBorder(15, 0, 0, 0), tabbedPane.getBorder()));
// tabbedPane.addTab("Option",optionPanel);
tabbedPane.addTab("User Data", userData);
tabbedPane.addTab("Wind1 ", windOnePane);
tabbedPane.addTab("Wind2", windTwoPane);
setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
add(tabbedPane, BorderLayout.CENTER);
add(optionPanel, BorderLayout.NORTH);
}
}
What should be done....
I am very thankful for the cooperations....
Best Regards,
Sarwar
- 09-27-2010, 02:46 PM #2
You need to put panels etc inside a JFrame, and make the frame visible.
Lesson: Using Swing Components (The Java™ Tutorials > Creating a GUI With JFC/Swing)
berkeleybross
- 09-27-2010, 02:49 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
All JComponents should be stuck to a JFrame or JWindow or JDialog (a so called 'top level component'). They can't be displayed on their own.
kind regards,
Jos
edit: too slow again, sigh ...Last edited by JosAH; 09-27-2010 at 03:03 PM.
- 09-27-2010, 03:03 PM #4
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
That worked....
Great... Thanks.....
And In order to make an executable file (I think jar file), do I need to add some thing... because after running it, I get .class files and they dont run directly.....
As I am running this program in the Eclipse... so it is working...
Any Idea....
Many Thanks....
Best Regards,
Sarwar
- 09-27-2010, 03:05 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
This is the new code and is working now...
public class WindAnalysis{
/**
* @param args
*/
public static void main(String[] args) {
// Auto-generated method stub
try {
UIManager.setLookAndFeel(new WindowsLookAndFeel());
}catch (Exception e) {
}
JFrame f = new JFrame("Wind Analysis");
f.setSize(800, 600);
MainPanel mainPanel = new MainPanel();
f.add(mainPanel);
f.setVisible(true);
}
}
Many Thanks for the help....
- 09-27-2010, 03:32 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
That code should strictly be in a SwingUtilities.invokeLater() call...can't guarantee the names there, though.
- 09-27-2010, 03:58 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
Hello,
I am trying to build an execuatble jar file for the application....
I am follwing the method as given in the link below:
FAQ How do I create an executable JAR file for a stand-alone SWT program? - Eclipsepedia
But every time I get a jar file and i try to run it... It gives a warning/error window saying Fail to load main class... Any idea...
or some other way to creat executable jar file for the application....
Many Thanks....
Best Regards,
Sarwar
- 09-27-2010, 03:59 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Print the full text of the error.
- 09-27-2010, 04:20 PM #9
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
It says:
Failed to load Main-Class manifest attribute from C:\User\....(jar file destination)
Any idea....
Do I need to creat the folder under the same Java project folder to get jar file.... because it says runtime folder
Thanks
- 09-27-2010, 04:47 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Your Main-Class should point to your class, not physically, but as package.class.
So "Main-Class: mypackage.myclass".
Not "Main-Class: C:\Something\etc\mypackage\myclass".
- 09-27-2010, 05:05 PM #11
To get a better error message that you can copy and paste here, execute the java program in a command prompt window:
java -jar YOURJARFILENAME
Then copy all of the command prompt window and paste it here.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
- 09-27-2010, 10:06 PM #12
Is it really easier to find how to post in garish colors that make unformatted code even more unreadable than it is to discover the correct way to post code?
/rant
db
- 09-28-2010, 01:39 AM #13
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
Hello...
When I try to execute the jar file in command prompt.... It says
Unable to access jar file WindAnalysis
Note that the project also uses some external jar file libraries... And I inculde them in a subfolder in the same folder that contains my project jar file "windanalysis.jar"....
I am very thankful for your cooperations.....
Regards
- 09-28-2010, 01:50 AM #14
Please copy the full contents of the command prompt showing what you entered and the full error message.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
- 09-28-2010, 03:24 AM #15
Norm is either incredibly patient, or colorblind ;)
- 09-28-2010, 03:40 AM #16
I ignore a lot of stuff. You're right about that first color. It is very annoying.
- 09-28-2010, 08:39 AM #17
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
In addition to what Norm has requested, also post the Manifest from you jar file.
- 09-28-2010, 10:41 AM #18
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
Hello....
This is what I get while using the command prompt.....
Directory of C:\Users\Logic Energy\Desktop\JarTest
28/09/2010 01:09 <DIR> .
28/09/2010 01:09 <DIR> ..
28/09/2010 01:09 32,259 windspeed.jar
28/09/2010 01:09 <DIR> windspeed_lib
1 File(s) 32,259 bytes
3 Dir(s) 81,739,833,344 bytes free
C:\Users\Logic Energy\Desktop\JarTest>java -jar windspeed
Unable to access jarfile windspeed
C:\Users\Logic Energy\Desktop\JarTest>
Just to make a few thing clear....
Actually Its the same project.... At first It was divided in two packages under the one project "WindAnalysis".... Then just to avoid confusion, I have built exactly same project but within one default package and named that "WindSpeed" and so is the main class name "WindSpeed"......
It runs in Eclipse.... Every thing is similar....
In cmd, The sub folder windspeed_lib contains the external libraries jar files.... This is created when I choose the option Export> runnable jar in Eclipse.....
One more thing... There is a folder called "resource" that contains image files / logos etc... and that is also used by the program.... Eclipse gives me error when that folder "resource" is not there.... But as soon as I copy and paste that folder in the "bin" folder of my project (in the workspace).... The project Runs... Do I need to copy and paste that folder in the folder JarTest that conatins that jar file "windspeed.jar" or what ...... ?????
The manifest text file... well that is not in the target jar file folder "JatTest"... But yes that is in the folder "WindSpeedJar" that I created in Eclipse under my project.... and it contains the follwing text:
Manifest-Version: 1.0
Class-Path: swt.jar
Main-Class: WindSpeed.WindSpeed
Thanks a lot for your help....
Regards,
Sarwar
- 09-28-2010, 10:55 AM #19
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
Hello .....
It has started working.....
What I did is that
1- I copied the swt.jar file in that folder as well.....
2- I also copied the "resource" folder that contains the image files etc.. for project in that folder..
3- Then I did the same thing.... Export> Runnable Jar.... (also selected the option "package required libraries into the runnable jar" )
It is working Now.....
Thanks very much for all your support.... :)
Best Regards,
Sarwar
- 09-28-2010, 11:12 AM #20
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
How do I add my JPanel
By Chanbre in forum NetBeansReplies: 13Last Post: 08-06-2010, 10:04 PM -
Running a program in a JPanel
By ttelloow in forum Advanced JavaReplies: 5Last Post: 07-26-2010, 06:18 PM -
JPanel
By Jitendra Shukla in forum AWT / SwingReplies: 11Last Post: 04-27-2010, 05:16 AM -
Problem in running Java swing wizard in jre 1.6 while it is running in jre 1.4
By Sanjay Dwivedi in forum AWT / SwingReplies: 0Last Post: 08-26-2009, 01:03 PM -
How to use Jpanel
By Manfizy in forum NetBeansReplies: 0Last Post: 02-19-2009, 12:34 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks