Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JOptionPane

Posted on 2005-05-11
19
Medium Priority
?
616 Views
Last Modified: 2008-02-26
As regarded in my previous questions.

I have a tabbed layout, so that each tab has it's own list of checkboxes.

I put a listener on the TabbedPane so that when a tab is selected, a JOptionPane is put at the bottom of the TabbedPane, istead of having it popup.

I put two buttons in there, Run All and Run Selected.

My issue is two fold.

First off, is it ok to use a JOptionPane in this manner, is there a better way to put buttons at the bottom of the list of checkboxes?

And if this is ok, how do I get rid of the default message and "ok" button that is thrown down with the JOptionPane.

I just need two buttons, one that runs all the checkboxes and one that runs only the selected checkboxes.

Thank you,
0
Comment
Question by:k41d3n
  • 9
  • 6
  • 4
19 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13977901
You should probably create your own dialog subclass. Do you mean the pane is *fixed* to another component?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13977902
>> is there a better way to put buttons at the bottom of the list of checkboxes?
Yes: make your own JPanel containing just the two buttons you want.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1000 total points
ID: 13977935
You  only need one component with buttons on it situated south of the tabbed pane from what i can tell
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:zzynx
ID: 13977938
>> so that when a tab is selected, a JOptionPane is put at the bottom of the TabbedPane,
Not sure I understand what behaviour exactly you want...

Selecting another tab => button panel should appear
So in fact it is always there?

>> istead of having it popup
Whe you pop it up you force the user to press one of the buttons.
When it is at the bottom, can they ignore it?
0
 
LVL 2

Author Comment

by:k41d3n
ID: 13977940
Yes, the Pane is fixed to another component.

I'll try to make my own panel with 2 buttons.

0
 
LVL 37

Expert Comment

by:zzynx
ID: 13977954
>> So in fact it is always there?
Oh, maybe it disappears once one of the buttons is pressed.
Stays the problem of ignoring it...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13977976
>>I'll try to make my own panel with 2 buttons.

Yes, you should probably make the buttons active only when one or more of the checkboxes on the active tab is selected
0
 
LVL 37

Accepted Solution

by:
zzynx earned 1000 total points
ID: 13977978
>> I'll try to make my own panel with 2 buttons.
That's OK.

JPanel buttonPanel = new JPanel();
JButton runAllBtn = new JButton("Run All");
JButton runSelBtn = new JButton("Run Selected");
buttonPanel.add( runAllBtn );
buttonPanel.add( runSelBtn );

But again:
>> Not sure I understand what behaviour exactly you want...
What's the flow logic?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13978003
>> make the buttons active only when one or more of the checkboxes on the active tab is selecte
For the "Run Selected" button that's a good idea.
But not for the "Run All" button, since I think that's just the goal of the button (not having to select all checkboxes)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13978026
k41d3n,
What if the user wants to switch to another tab without running something at all (not the selected and not all of them)?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13978061
>>What if the user wants to switch to another tab without running something at all (not the selected and not all of them)?

What's to prevent them?
0
 
LVL 2

Author Comment

by:k41d3n
ID: 13978429
Ok, the way it works is that there are 3 tabs:

HTTP
TELNET
Results

the HTTP and the TELNET Tabs all have 5 tabs underneat them.

ALARM Threshold
Board Only
Configuration
Module Conf
PCIOM
RUG Conf

The default tab is HTTP -> Alarm Threshold.

So when a user starts the GUI, there should be tests under alarm threshold with  run all and run selected buttons to gather the information from the checked boxes and run the method (stil have to figure that out too, one step at a time)

I made my own button pane that has the two buttons in them, and made it so that it would only show up when you select HTTP  -> Configuration

Obviously these buttons should show up for all tabls that are test related, , i.e; HTTP or TELNET and any sub tab selected.

Then the buttons need to get the values from checkboxes on the current selected tab.

I like the idea of not showing the run selected unless 1 or more tests are selected, again, my Swing knowledge is so very low.....

So anyway, I chucked the optionpane and made my own panel for the buttons.

But it's showing up at the bottom of the whole GUI and not inside the tabbed pane like I would like it to, namely because I added it to the main pane. With the tabs having scrollpanes I can't do a borderlayout, it keeps saying I need a scrollpane layout. And the checkbox pane is a FlowLayout.

All these layouts are confusing, here is some code, the jScrollPane3 is the HTTP -> Configuration tab pane, I have the Checkboxes in there and then I also have my buttons pane.

    /**
     * This method initializes jScrollPane3
     *
     * @return javax.swing.JScrollPane
     */
    private JScrollPane getJScrollPane3() {
        if (jScrollPane3 == null) {
            jScrollPane3 = new JScrollPane();
            jScrollPane3.setViewportView(getJPaneCheckBox());
        }
        return jScrollPane3;
    }

    private JPanel getJPaneCheckBox() {
        JPanel insidePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));  
        JPanel jPanelCheckBox = new JPanel();  
        GridLayout checkbox = new GridLayout(0, 4);
        jPanelCheckBox.setLayout(checkbox);
        try {
            Set methods = GetTestMethods
            .findMethods(DeviceIdentification.class);
            System.out.println(methods.size());
            //these variables are defined private elsewhere in the class
            //For a set or list
            for (Iterator it = methods.iterator(); it.hasNext();) {
                Object listElement = it.next();
                String element = listElement.toString();
                System.out.println(element);
                JCheckBox newCheckBox = new JCheckBox(element);
                newCheckBox.setName(element);
                System.out.println(newCheckBox.getName());
                jPanelCheckBox.add(newCheckBox);
            }
        } catch (Exception e) {
            atelog.error(e);
            e.printStackTrace();
        }
        insidePanel.add(jPanelCheckBox);
        return insidePanel;  
    }

    /**
     * This method initializes jTestbuttonPane      
     *       
     * @return javax.swing.JTestButtonPane      
     */
    private JPanel getJTestButtonPane() {
        if (jTestButtonPane == null) {
            jTestButtonPane = new JPanel();
            jTestButtonPane.setLayout(new java.awt.BorderLayout());
            JPanel jPanelHttpTestButtons = new JPanel();
            GridLayout buttons = new GridLayout(1, 2);
            jPanelHttpTestButtons.setLayout(buttons);
            JButton runAll = new JButton("Run All");
            JButton runSelected = new JButton("Run Selected");
            jPanelHttpTestButtons.add(runAll);
            jPanelHttpTestButtons.add(runSelected);
            jTestButtonPane.add(jPanelHttpTestButtons);
            jTestButtonPane.setVisible(false);
        }
        return jTestButtonPane;
    }

   /**
     * This method initializes jPanel1
     *
     * @return javax.swing.JPanel
     */
    private JPanel getJPanel1() {
        if (jPanel1 == null) {
            jPanel1 = new JPanel();
            jPanel1.setLayout(new BorderLayout());
            jPanel1.add(getJPanel(), java.awt.BorderLayout.NORTH);
            jPanel1.add(getJTabbedPane2(), java.awt.BorderLayout.CENTER);
            jPanel1.add(getJTestButtonPane(), java.awt.BorderLayout.SOUTH);
        }
        return jPanel1;
    }
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13978500
>> GridLayout checkbox = new GridLayout(0, 4);
Sure about that 4? ;°)
0
 
LVL 2

Author Comment

by:k41d3n
ID: 13978529
haha yes, sorry. My scrollpane is big, so 2 columns barely filled it. 4 across fits nicely with room to grow :)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13978632
Now, could you formulate what's the problem you want us to handle?
0
 
LVL 2

Author Comment

by:k41d3n
ID: 13978656
I'll carry it over to a new question, as you did handle this one already.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13978676
ok ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13978702
:-)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13978709
thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question