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

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

Related

Netbeans adding actions to output window

I have a netbeans platform application,
The Output window consists of two tabs in which am able to embed one of the tab in to a separate component with the following reference,
http://wiki.netbeans.org/DevFaqOWTabEmbedding
However, when i tried adding actions to it , the actions are not coming up in UI .
IOContainer ioc = IOContainer.create(new IOC());
InputOutput io = IOProvider.getDefault().getIO("test",
new Action[]{
new OneAction(),
new TwoAction(),
new ThreeAction()},ioc);
am expecting the three actions to be shown in the newly created window.
Something like this,
But am getting only the white window.
However, if i don't embed the tab in to another component, the actions appear.
Any help?
IOC has empty implementation of IOContainer.Provider method
setToolbarActions(JComponent comp, Action[] toolbarActions)
you should add JToolbar in IOC and implement that method.

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

Displaying a JFrame as the result of a JButton click?

I am trying to create a JPanel to display when a user clicks a button within my main JFrame. In Netbeans I first used the wizard to add a new JPanel to my project, I then used the GUI creator to fill in all the content. I am not trying to display the JPanel with the following code
private void m_jbShowSelAccResultsActionPerformed(java.awt.event.ActionEvent evt)
{
Account selAcc = getSelectedAccount();
if(selAcc != null)
{
AccountView accPanel = new AccountView(Account.getDeepCopy(selAcc));
accPanel.setVisible(true);
}
else
ShowMessage("Please select an account to view");
}
But nothing happens, no error is thrown and the JPanel is not shown. So I then changed the JPanel to a JFrame (Netbeans didn't complain). When I try again with the same code I receive the error GroupLayout can only be used with one Container at a time.
How can I display my JPanel/JFrame?
To change views within a Swing GUI, use a CardLayout as this is a much more robust and reliable way to do this.
Don't try to blindly "change a JPanel to a JFrame". It looks like you're just guessing here.
GroupLayout can't be reused as the error message is telling you. Likely this error comes from the point above. If you avoid trying to make a JFrame out of a JPanel, the error message will likely go away. As an aside, GroupLayout is not easily used manually, especially if you're trying to add components to an already rendered GUI.
So for instance, if your program had a JPanel say called cardHolderPanel, that used a CardLayout, this held by a variable say called cardLayout, and you've already added a "card" JPanel to this holder for accounts, say called accPanel, and if the accPanel had a method to set its currently displayed account, say setAccount(Accoint a), you could easily swap views by calling the CardLayout show(...) method, something like:
private void m_jbShowSelAccResultsActionPerformed(java.awt.event.ActionEvent evt) {
Account selAcc = getSelectedAccount();
if(selAcc != null) {
accPanel.setAccount(Account.getDeepCopy(selAcc));
cardLayout.show(cardHolderPanel, "Account View");
}
else {
showErrorMessage("Please select an account to view");
}
}

Chart Wont Show When I Run It?

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.

Text Missing On Checkbox Component for Swing After Adding Action

I'm writing a simple Swing app. I tried adding a checkbox as listed below. Once I added the actionHandler loadPickers the name Foo disappeared from where it was sitting next to the right of chckbxNewCheckBox. I tried adding a call to setHideActionText(), but now nothing displays.
JCheckBox chckbxNewCheckBox = new JCheckBox("Foo");
chckbxNewCheckBox.setToolTipText("");
chckbxNewCheckBox.setName("");
chckbxNewCheckBox.setHideActionText(true);
chckbxNewCheckBox.setAction(loadPickers);
mainPanel.add(chckbxNewCheckBox, "flowy,cell 0 1");
If I change it to this it works properly. I see the text "Foo".
JCheckBox chckbxNewCheckBox = new JCheckBox("Foo");
chckbxNewCheckBox.setToolTipText("");
chckbxNewCheckBox.setName("");
chckbxNewCheckBox.setHideActionText(true);
chckbxNewCheckBox.setAction(loadPickers);
chckbxNewCheckBox.setText("Foo"); //THIS DOES NOT WORK IF IT COMES BEFORE SET ACTION
mainPanel.add(chckbxNewCheckBox, "flowy,cell 0 1");
I've included the action here for completeness. Why does it work this way? Am I missing something here? Currently I'm using the WindowBuilder plugin for Eclipse with the Mig layout system (which I really like). Unfortunately I haven't figure out if there's a way to make WindowBuilder use the .setText() method instead of using the constructor. Any help on what I'm doing wrong, any insight on why this behavior exists like this, or a good workaround for WindowBuilder would be great.
private class LoadPickers extends AbstractAction {
public LoadPickers() {
//putValue(NAME, "SwingAction_2");
putValue(SHORT_DESCRIPTION, "Some short description");
}
public void actionPerformed(ActionEvent e) {
}
}
As explained in the JavaDoc of AbstractButton.setAction:
Setting the Action results in immediately changing all the properties described in Swing Components Supporting Action. Subsequently, the button's properties are automatically updated as the Action's properties change.
So all the following properties can be impacted by setting an action:
enabled
toolTipText
actionCommand
mnemonic
text
displayedMnemonicIndex
icon (NA for JCheckBox)
accelerator (NA for JCheckBox)
selected

Categories

Resources