Chart Wont Show When I Run It? - java

I'm trying to make a simple pie chart appear on a jpanel in netbeans with JFreeChart and got this:
public void createPieChart()
{
DefaultPieDataset myPie = new DefaultPieDataset();
myPie.setValue("Apples",new Integer(12));
myPie.setValue("Oranges",new Integer(23));
myPie.setValue("Mangos",new Integer(7));
myPie.setValue("Pears",new Integer(22));
JFreeChart myChart = ChartFactory.createPieChart3D("Damo's Fruit Sales", myPie,true,true,true);
PiePlot3D pie3D = (PiePlot3D)myChart.getPlot();
ChartPanel myPanel = new ChartPanel(myChart);
lowerMain_PNL.removeAll();
lowerMain_PNL.add(myPanel,BorderLayout.CENTER);
lowerMain_PNL.revalidate();
}
I get no compiler errors and when it runs the window appears with the button, but when I press the button my pie chart doesn't appear. Anyone know what I could be missing?

Check the layout manager of lowerMain_PNL. Netbeans form designer uses GroupLayout by default, so unless you changed it, that's what you got. Adding to a container using GroupLayout at run time is tricky, especially if the component contains more than one subcomponent (And requires adding components to the layout, instead of using the usual add() methods).
Change it to BorderLayout instead, since you are using BorderLayout constraints.

Related

Set the size of Vaadin GridLayout as the ScreenSize in java

i'm using Vaadin GridLayout in a project, and i want to make it big as the screen so i can arrange the UI of the app.
i'm a beginner in java, i tried .setWidth("100%"); , and also tried
to get the Screen resolution with Toolkit, but it did'nt help.
i've already searched around but none could've helping me.
can anyone give me a hint?
here is a part of it:
filter.setWidth("100%"); //TextField
entryList.setWidth("100%"); //Table
entryList.setHeight("100%");
blayout.addComponents(addNew,delete); //HorizontalLayout
blayout.setStyleName("buttons");
Styles style=Page.getCurrent().getStyles();
style.add(".buttons {float:right;}");
layout1.setMargin(true); //VerticalLayout
layout1.setSpacing(true);
layout1.addComponents(filter,entryList,blayout);
layout1.setWidth("100%");
layout1.setHeight("100%");
layout1.setSizeFull();
layout2.setSizeFull(); //VerticalLayout
layout2.addComponent(form); // form is a variable of an other class
layout2.setWidth("100%");
layout2.setHeight("100%");
MPanel panel1=new MPanel("Search");
MPanel panel2=new MPanel("Edit");
panel1.setSizeFull();
panel2.setSizeFull();
panel1.setContent(layout1);
panel2.setContent(layout2);
panel1.setWidth("100%");
panel1.setHeight("100%");
panel2.setWidth("100%");
panel2.setHeight("100%");
mlayout.setRows(1); //GridLayout
mlayout.setColumns(2);
mlayout.addComponent(panel1,0,0);
mlayout.addComponent(panel2,1,0);
mlayout.setSpacing(true);
addComponents(new MVerticalLayout(menue, mlayout)); //Creates Output

Only one gwt-chart visible

I'm trying to display multiple charts in a gwt-Project using the gwt-charts library but just the last created chart is visible no matter what layout or which widget I use.
TableExample is identical to this: http://gwt-charts.appspot.com/#table
Then add the charts to the main panel like this:
private DockLayoutPanel mainPanel = new DockLayoutPanel(Unit.EM);
private TabLayoutPanel tabLayoutPanel = new TabLayoutPanel(1.5, Unit.EM);
#Override
public void onModuleLoad() {
Window.enableScrolling(false);
Window.setMargin("0px");
tabLayoutPanel.add(new TableExample(), "Here should the first table be");
tabLayoutPanel.add(new HTML("Lorem ipsum dolor sit amet"), "Lorem");
tabLayoutPanel.add(new TableExample(), "Only visible table");
tabLayoutPanel.add(new HTML("ga ga ga lalasdf a3ifa"), "Other text");
mainPanel.add(tabLayoutPanel);
RootLayoutPanel.get().add(mainPanel);
}
The two tabs with HTML and the second TableExample show the correct content but the first tab with the TableExample is empty.
Does anyone know why one only gwt-chart is visible? I don't get any error messages or something.
The problem is that TableExample draws the chart only after the Runnable is executed after the chart api is loaded. When you create two TableExamples they both try to load the chart api but only one of them succeeds and thus only one of the Runnables is called.
To fix it you need to load the chart api just once -- perhaps when your app first loads. Then TableExample can be changed to just draw itself without having to first load the api.

Replacing ButtonGroupPanel from com.symantec.itools.javax.swing package

I am migrating 'Java Swing' code from 'Java Visual Cafe' JDK1.2 to 'Eclipse SDK6'. In Visual Cafe it has code is like this:
public Sample extends JPanel(){
.....
package com.symantec.itools.javax.swing.JButtonGroupPanel bgAcc = new com.symantec.itools.javax.swing.JButtonGroupPanel();
....
bgAcc.setBorder(tbAcc); //tbAcc is titledBorder component type
..
bgAcc.setBounds(0,108,400,76);
...
bgAcc.add(bgLb); // bgLb is JLabel component type
..
bgAcc.add(button1, new GridBagConstraints(...));
..
}
Can anyone suggest how I can replace this code in Eclipse SDK6? I am unable find these methods for 'ButtonGroup' in 'Swing'.
I am not familiar wit the JButtonGroupPanel class, but those methods you use are all available on a regular JPanel as well.
ButtonGroup is a completely different concept in Swing then a JPanel. A ButtonGroup is for example used to group a set of JRadioButtons, and makes sure that only one radio button in that group can be selected at the time. But a ButtonGroup is not a JComponent nor a Container, so of course you will not find methods like setBorder on it.
Side-note: do not port those setBounds calls. Use a decent LayoutManager instead

How to merge JOptionPane and Frame into one

Currently I have a very basic file viewer working as follows :
- in JOptionPane I browse for files, and set some variables to display (colors, line connecting etc)
- previous windows loads a frame with drawn points
alt text http://img190.imageshack.us/img190/4443/104bu.jpg
Code :
http://paste.pocoo.org/show/220066/
Now I'd like to throw it into one window, with JMenu for selecting files and changing display parameters. How to get started ? Should I rewrite everything to JDialog ?
alt text http://img684.imageshack.us/img684/5264/lab10db.jpg
If you want the JOPtionPane as a child of the main JFrame, then add it as a child. Of course it will then cover your dots. Hence you will have to not draw your dots directly in the content pane of the main JFrame, but rather in a new JPanel that you have also added to the JFRame's content pane. Let me know if I've understood the question whatsoever.
Here's some code for how I see the setup (I'm leaving the layout problem out of this, partly because it depends on what you want to see):
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setSize(new Dimension(400,400));
frame.getContentPane().add(new JOptionPane());
JPanel canvasForDots = new JPanel();
frame.getContentPane().add(canvasForDots);
You might also like to look at How to Use Tool Bars and How to Use Menus. ImageApp is a typical implementation that associates menu items with the corresponding Action instances.
private class ClearAction extends AbstractAction {…}
private class ImageOpenAction extends AbstractAction {}
private Action openAction = new ImageOpenAction("Open");
private Action clearAction = new ClearAction("Clear");
…
JMenu menu = new JMenu("File");
menu.add(new JMenuItem(openAction));
menu.add(new JMenuItem(clearAction));
This related example adds the file chooser directly to the main frame. Here's a more elaborate example of connecting lines and shapes using the same principles.

setting Swing JInternalFrame lnf manually

UIManager.put("InternalFrame.activeTitleBackground", new ColorUIResource(new Color(207,255,247)));
UIManager.put("InternalFrame.inactiveTitleBackground", new ColorUIResource(new Color(207,255,247)));
JDesktopPane baTabbedPane = new JDesktopPane();
JInternalFrame iframe = new JInternalFrame("Cheapest To Deliver",true,true,true,true);
iframe.setSize(400,150);
baTabbedPane.add(iframe);
why is my Internal Frame's title background not set on startup?
I've tried setting it on the overall JFrame init but made no difference (By contrast I could change other JFrame ui component look n feel such as MenuItem.background in this location so I thought it might have been because the JInternalFrame was not a top-level component i.e. under a tabbed pane, that maybe it needed changing at some other point, but where?)
Any tips on the correct place to call UIManager.put() for JInternalFrame?
got it eventually - the call to put() works fine after JInternalFrame creation but I did make it before I added the component to a container. I then still had to set it's UI:
JInternalFrame iframe = new JInternalFrame("blah",true,true,true,true);
UIManager.put("InternalFrame.activeTitleBackground", new ColorUIResource(new Color(248,250,175)));
UIManager.put("InternalFrame.inactiveTitleBackground", new ColorUIResource(new Color(248,250,175)));
javax.swing.plaf.basic.BasicInternalFrameUI ui =
new javax.swing.plaf.basic.BasicInternalFrameUI(iframe);
iframe.setUI(ui);
I think you need to make all calls to UIManager.put before you create any Swing components.

Categories

Resources