Adding panel to scrollpane on button click

Please run the below code with
javac MyTestingNew.java and
java MyTestingNew
I am having a button(ADD ME) on click of that I want to add panel containg textfield
which will append to already exist textfields which are diasplyed in jscrollpane
How I can proceed??
import javax.swing.*;
import java.awt.Dimension;
import java.awt.event.*;
class MyTestingNew extends JFrame{
     static Sale2 sale2;
     static int coordinate = 0;
     final int SIZE = 5;
       JPanel[] jp = new JPanel[20];
   //     ButtonGroup[] group = new ButtonGroup[SIZE]; 
   //     JRadioButton[] rb = new JRadioButton[SIZE * SIZE];
     JTextField[] jtf = new JTextField[SIZE * 1000];
     JButton jb = new JButton();
        public MyTestingNew(){
             buildGUI(); 
    public void buildGUI(){   
         setSize(1200,800);   
         //setLocation(400,300);  
          setDefaultCloseOperation(EXIT_ON_CLOSE);  
          JPanel main = new JPanel();
         //JPanel main = new JPanel(new GridLayout(20,1));
         main.setLayout(null);
         jb.setText("ADD ME");
         jb.setBounds(0,0,100,30);
         sale2=new Sale2(this);
         jb.addActionListener(sale2);
         main.setPreferredSize(new Dimension(353,800));
         //main.setBounds(420,335,353,381);
         //main.setBounds(0,0,353,381);
         for(int x = 0; x <20; x++){
               //group[x] = new ButtonGroup();    
            jp[x] = new JPanel();
                //jp[x] = new JPanel(new GridLayout(1,SIZE));
              jp[x].setLayout(null);
              jp[x].setBounds(0,coordinate,353,32);
              //jp[x].setBounds(0,coordinate,353,32);
                System.out.println("SIZE  :"+ SIZE);
            jp[x].setBorder(BorderFactory.createEtchedBorder());   
            for(int y = 1; y < SIZE+1; y++){
                 int rbNum = x*SIZE + y;
                 System.out.println("X : "+x+ "Y : "+y+" rbNum : "+rbNum);
                 if(y==1) {jtf[rbNum] = new JTextField(""+rbNum);jtf[rbNum].setBounds(0,0,30,32);}
                 if(y==2) {jtf[rbNum] = new JTextField(""+rbNum);jtf[rbNum].setBounds(32,0,180,32);}
                 if(y==3) {jtf[rbNum] = new JTextField(""+rbNum);jtf[rbNum].setBounds(214,0,35,32);}
                 if(y==4) {jtf[rbNum] = new JTextField(""+rbNum);jtf[rbNum].setBounds(251,0,35,32);}
                 if(y==5) {jtf[rbNum] = new JTextField(""+rbNum);jtf[rbNum].setBounds(288,0,65,32);}
                jp[x].add(jtf[rbNum]);  
                 coordinate = coordinate + 7;
            main.add(jp[x]);   
        JScrollPane sp = new JScrollPane(main);
         //sp.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
         sp.setBounds(420,335,353,350);
         JPanel main2 = new JPanel();
         main2.setLayout(null);
         //main2.setPreferredSize(new Dimension(400,400));
         main2.add(sp);
         main2.add(jb);
         getContentPane().add(main2);
       public static void main(String[] args){
               new MyTestingNew().setVisible(true);
class Sale2 implements ActionListener
MyTestingNew parent;
Sale2(MyTestingNew parent)
this.parent=parent;
public void actionPerformed(ActionEvent e)
     //My code will come here
     System.out.println("get from button");
}

You really should start learning how to use LayoutManagers.. they make life a lot easier
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MyTestingNew extends JFrame {
    final int SIZE = 5;
    JPanel[] jp = new JPanel[20];
    JTextField[] jtf = new JTextField[SIZE * 1000];
    JButton jb = new JButton();
    private int nrOfRows = 20;//starting nr of rows
    public MyTestingNew() {
        buildGUI();
    public void buildGUI() {
        setTitle("My Test");
        setSize(1200, 800);
        //setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        final JPanel main = new JPanel();
        //JPanel main = new JPanel(new GridLayout(20,1));
        main.setLayout(new BoxLayout(main,BoxLayout.Y_AXIS));
        jb.setText("ADD ME");
        jb.setBounds(0, 0, 100, 30);
        jb.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evt){
                JPanel newPanel = new JPanel();
                newPanel.setLayout(new GridLayout(1,SIZE));
                for (int y = 1; y < SIZE + 1; y++) {
                    int rbNum = nrOfRows * SIZE + y;
                    System.out.println("X : " + nrOfRows + " Y : " + y + " rbNum : " + rbNum);
                    newPanel.add(new JTextField("" + rbNum));
                main.add(newPanel);
                main.revalidate();
                nrOfRows++;//added a new row
        for (int x = 0; x < nrOfRows; x++) {
            jp[x] = new JPanel();
            jp[x].setLayout(new GridLayout(1,SIZE));
            System.out.println("SIZE  :" + SIZE);
            for (int y = 1; y < SIZE + 1; y++) {
                int rbNum = x * SIZE + y;
                System.out.println("X : " + x + " Y : " + y + " rbNum : " + rbNum);
                jtf[rbNum] = new JTextField("" + rbNum);
                jp[x].add(jtf[rbNum]);
            main.add(jp[x]);
        JScrollPane sp = new JScrollPane(main);
        //sp.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        sp.setBounds(420, 335, 353, 350);
        JPanel main2 = new JPanel();
        main2.setLayout(null);
        //main2.setPreferredSize(new Dimension(400,400));
        main2.add(sp);
        main2.add(jb);
        getContentPane().add(main2);
    public static void main(String[] args) {
        new MyTestingNew().setVisible(true);
}

Similar Messages

  • Adding panels to scrollpane

    I want to include panels dynamically into the scroll pane. Which layout should I select for this ? I read that for scroll panes, only ScrollPaneLayout can be used, but it does not work for my application. Can anyone tell me please how do I add the panels to it ? The code I m using is as follows:
    jScrollPaneMain.setLayout(new ScrollPaneLayout());
    jScrollPaneMain.add(jPanel1);
    jScrollPaneMain.revalidate();
    jScrollPaneMain.repaint(); 

    Make an intermediate panel:
    JPanel intermediate = new JPanel();
    scrollPane.setViewportView(intermediate);and then:
    intermediate.add(panel1);
    intermediate.add(panel2);The layout for the intermediate panel could be a GridLayout, GridBagLayout or a GroupLayout. Depending on how the added panels have to behave.

  • Show/hide panels on button click

    Hello,
    I have to show/hides several panels on same palette on some button actions. I am trying to check whether it is possible to add each child panel in different .fr files.
    Just to brief,  On panel I have different icon buttons and on each button I have to show different view in the main panel thus I cannot use tabular dialog. Please help me to find a way to achieve this?
    I tried following code
    I have Created two primary resource panel in TestSample1.fr,TestSample2.fr files respctively.
    My main panel (Palette panel) have two buttons (TestSample1Button,TestSample2Button).
    I want to show/hide these panels on button click in main panel.
    InterfacePtr<IPanelControlData> parentPanelCtrlData(Utils<IPalettePanelUtils>()->QueryPanelByWidgetID(kMainPanelWidgetID) ); // main panel
    if(parentPanelCtrlData)
        InterfacePtr<IControlView>         testSample1PanelPanelView((IControlView*)::CreateObject(::GetDataBase(this),kTestSample1P anelWidgetBoss,IID_ICONTROLVIEW));
        if(testSample1PanelPanelView)
            parentPanelCtrlData->AddWidget(testSample1PanelPanelView);
    I have added above code on TestSample1Button observer.But it is not working.
    is It possible? can anybody help me?

    Yes it is possible.
    I am not sure but following line of code also needed after adding widget .
    testSample1PanelPanelView->ForceRedraw(testSample1PanelPanelView->GetDrawRegion(), kTrue);

  • Automatic Resizing of panel with drawings added to a scrollPane

    I have a Panel with rectangles text and arcs drawn .and it is added to a scrollPane.both vertical and Horizontal scrollbars are enabled for scrollPane.My problem is that i have to draw arcs connecting these rectangles with text enclosed in it. and when i connect two rectangles a span is formed connecting the two..and as hierarchy goes deeper ie connecting spans of already linked rectangles with similar spans..There wont be enough space at top for arc to be drawn..So ive to either readjust all objects related with drawings in panel or is there any other way to increase panel size automatically as drawings need more space..Please suggest me some method for this problem

    Panels Preffered size is set as (3000,1000) and TextRectangles are drawn in panel Cordinates of textRectangle are set in setTextRectangle method and all further drawings connecting rectangle are done by mouse clicks on specific rectangles.
    and layout in setTextRectangle is TextLayout of the text enclosed in rectangles.So when i coordinates for arc drawn exceeds the panel should i call separate method for resetting panel size is that what you have suggested
       screen_Resolution = Toolkit.getDefaultToolkit().
                               getScreenResolution();
             screen_Width = Toolkit.getDefaultToolkit().
                               getScreenSize().width;
             screen_Height = Toolkit.getDefaultToolkit().
                              getScreenSize().height;
    public void setTextRectangle(Graphics g, Font font)
              Graphics2D g2 = (Graphics2D) g;
             FontMetrics metrics= g.getFontMetrics (font);
            int textHeight = metrics.getHeight();
            int left=textHeight;
            int yCordRectangle=(int)(screen_Height/5);
            for (int i = 0; i < layouts.size (); i++) {
                 int top=(int)(screen_Resolution*2);
                 for (int j = 0; j < layouts.get (i).size (); j++) {
                     top += textHeight;
        TextRectangle textRectangle=new TextRectangle(left,yCordRectangle,wrapWidth,top-150);
         addtoarray( textRectangle, rectangles);
        left += wrapWidth + textHeight;
       

  • Programmatically Open and close panel accordion on button click

    Hi All,
    Im using JDev 11.1.1.4 and adf faces application.
    My requirement is to open/close panel accordion on button click programmatically.Kindly have a look at below figured one
    Panel accordion Open Button
    | ShowDetail1 //Consider first one is open inside close button is there to close this pane..
    |
    |
    |
    Close Button
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Show detail2 open button
    Show details3 open button
    Any idea...
    Thanks,

    Thanks Mr.frank...
    But disclosed property is to make the showdetail to disclose or not.. but requirement is to open panel accordion on button click
    By default using panel accordion have arrow icon in left to open in a same way if i open the second one, first will get close automatically...
    Actually is there any way to do the default process (open/close) programmatically...

  • Scrollpane scrolldrag and button click problem.

    Hi all,
         i dublicate my  movieclip named mc2. (mc2 in mc1 moviclip). And my scrollpane 's contentpath is mc1. When i do that, it works. but if i make scrolldrag = true, my button in my movieclip doesnt work.
    How can i use scrolldrag and button click in scrollpane  content ??
    thx
    Talha

    Hi,
    It works for me. i have a movie clip with button "my_btn". I placed this movie clip inside Scrollpane and enalbed scrollDrag property. I am able to drag the movie clip inside scroll pane. Also when i clicked the button inside the movie clip, i could see event handler getting triggered. I can also drag the movie clip by pressing mouse on the button.
    I am not sure whats wrong in your application.
    Thanks,
    Karthikeyan R.

  • Panels to be displayed when clicking on a button: general question

    Hi there,
    I want to design a GUI that will look something like:
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | A | B | C | D | E | F |
    That should be two panels:
    - bottom panel: just a some buttons (A, B, C...)
    - top panel: to start with, it'll be empty/blank, but when a button is pressed, some content should be displayed (buttons, labels, etc)
    So, my idea was to have a main UI class, where I would have both panels; and for each different button I'd also have a different class. These classes should just display their own panel within the "top panel".
    And that's what I'm not getting.
    In the main UI class, I wrote some instances for each possible class that I'd be calling. And each class would have a constructor:
    UITesting(Panel aPanel, String aWord)
    Where aPanel is the top panel from the main UI, and aWord just a word to display in a lable for example (just testing purposes).
    My question:
    how do I make visible panelA when I press the buttonA and so on?
    Anybody knows where I could find a similar example or tutorial?
    Thanks!

    Try using a Card Layout.
    Giving an Example with two buttons.
    ====================================
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class TestDialog extends JDialog
         private JPanel p3 = new JPanel();
         private CardLayout cd = new CardLayout(0,0);     
         public TestDialog()
              init();
         public static void main(String[] args)
              System.out.println("Hello World!");
              TestDialog t = new TestDialog();
              t.setSize(200,200);
              t.pack();
              t.setVisible(true);
         private void init()
              JPanel p1 = (JPanel)this.getContentPane();
              p1.setLayout(new BorderLayout(0,0));
              JPanel p2 = new JPanel();
              JButton b1 = new JButton("Button1");
              JButton b2 = new JButton("Button2");
              p2.setLayout(new FlowLayout(FlowLayout.CENTER, 0,0));
              p2.add(b1);
              p2.add(b2);
              p1.add(BorderLayout.SOUTH, p2);
              p1.add(BorderLayout.CENTER, p3);
              p3.setLayout(cd);
              JPanel p4 = new JPanel();
              JPanel p5 = new JPanel();
              p4.add(new JLabel("Panel1"));
              p5.add(new JLabel("Panel2"));
              p3.add("Card1", p4);
              p3.add("Card2", p5);
              cd.show(p3, "Card1");
              b1.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        cd.show(p3, "Card1");
              b2.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        cd.show(p3, "Card2");

  • Problem in refreshing JTree inside Jscrollpane on Button click

    hi sir,
    i have problem in refreshing JTree on Button click inside JscrollPane
    Actually I am removing scrollPane from panel and then again creating tree inside scrollpane and adding it to Jpanel but the tree is not shown inside scrollpane. here is the dummy code.
    please help me.
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.tree.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    public class Test
    public static void main(String[] args)
         JFrame jf=new TestTreeRefresh();
         jf.addWindowListener( new
         WindowAdapter()
         public void windowClosing(WindowEvent e )
         System.exit(0);
         jf.setVisible(true);
    class TestTreeRefresh extends JFrame
         DefaultMutableTreeNode top;
    JTree tree;
         JScrollPane treeView;
         JPanel jp=new JPanel();
         JButton jb= new JButton("Refresh");
    TestTreeRefresh()
    setTitle("TestTree");
    setSize(500,500);
    getContentPane().setLayout(null);
    jp.setBounds(new Rectangle(1,1,490,490));
    jp.setLayout(null);
    top =new DefaultMutableTreeNode("The Java Series");
    createNodes(top);
    tree = new JTree(top);
    treeView = new JScrollPane(tree);
    treeView.setBounds(new Rectangle(50,50,200,200));
    jb.setBounds(new Rectangle(50,300,100,50));
    jb.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
              jp.remove(treeView);
              top =new DefaultMutableTreeNode("The Java ");
    createNodes(top);
              tree = new JTree(top);
                   treeView = new JScrollPane(tree);
                   treeView.setBounds(new Rectangle(50,50,200,200));
                   jp.add(treeView);     
                   jp.repaint();     
    jp.add(jb);     
    jp.add(treeView);
    getContentPane().add(jp);
    private void createNodes(DefaultMutableTreeNode top) {
    DefaultMutableTreeNode category = null;
    DefaultMutableTreeNode book = null;
    category = new DefaultMutableTreeNode("Books for Java Programmers");
    top.add(category);
    book = new DefaultMutableTreeNode("The Java Tutorial: A Short Course on the Basics");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Tutorial Continued: The Rest of the JDK");
    category.add(book);
    book = new DefaultMutableTreeNode("The JFC Swing Tutorial: A Guide to Constructing GUIs");
    category.add(book);
    book = new DefaultMutableTreeNode("Effective Java Programming Language Guide");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Programming Language");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Developers Almanac");
    category.add(book);
    category = new DefaultMutableTreeNode("Books for Java Implementers");
    top.add(category);
    book = new DefaultMutableTreeNode("The Java Virtual Machine Specification");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Language Specification");
    category.add(book);
    }

    hi sir ,
    thaks for u'r suggession.Its working fine but the
    properties of the previous tree were not working
    after setModel() property .like action at leaf node
    is not working,I'm sorry but I don't understand. I think you are saying that the problem is solved but I can read it to mean that you still have a problem.
    If you still have a problem then please post some code (using the [code] tags of course).

  • Resizing JFrame on button click to show an image on the JFrame

    Dear All,
    I have a JFrame which has an empty label. On button click I want to set an icon for the label and want the JFrame to be resized to show that icon. I am using frame.pack() and I am not using any other sizing function. The code that I have right now, prints the image on the panel, but does not resize the frame to show the image. Pleae could someone help.package gui;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    public class ComponentDemo extends JPanel implements ActionListener,
    ItemListener, MouseListener, KeyListener {
         private JTextArea textarea;
         private JButton button;
         private final static String newline = "\n";
         private JLabel imageIcon;
         public ComponentDemo() {
              button = new JButton("JButton welcomes you  to CO2001");
              button.addActionListener(this);
              add(button);
              textarea = new JTextArea(10, 50);
              textarea.setEditable(false);
              addMouseListener(this);
              textarea.addKeyListener(this);
              JScrollPane scrollPane = new JScrollPane(textarea);
              add(scrollPane);
              imageIcon = new JLabel();
              add(imageIcon);
              setBackground(Color.pink);
              new JScrollPane(this);
          * Create the GUI and show it. For thread safety, this method should be
          * invoked from the event-dispatching thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("Simple FrameDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              frame.setLocation(700, 200);
              // get the content pane and set the background colour;
              frame.add(new ComponentDemo());
         //     frame.setSize(screenSize);
              // frame.getContentPane().setBackground(Color.cyan);
              // Display the window.
              frame.pack();
              frame.setVisible(true);
              frame.setResizable(true);
         public static void main(String[] args) {
              // Schedule a job for the event-dispatching thread:
              // creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();
         @Override
         public void actionPerformed(ActionEvent e) {
              // TODO Auto-generated method stub
              if (e.getSource() instanceof JButton) {
                   // System.out.println(e.getSource());
                   String text = ((JButton) e.getSource()).getText();
                   textarea.append(text + newline);
                   textarea.setBackground(Color.cyan);
                   textarea.setForeground(Color.BLUE);
                   textarea.setCaretPosition(textarea.getDocument().getLength());
                   imageIcon.setIcon(createImageIcon("SwingingDuke.png",
                   "Image to be displayed"));
         @Override
         public void itemStateChanged(ItemEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mouseClicked(MouseEvent arg0) {
              textarea.append("A Mouse click welcomes you to CO2001" + newline);
              textarea.setBackground(Color.green);
              textarea.setCaretPosition(textarea.getDocument().getLength());
         @Override
         public void mouseEntered(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mouseExited(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mousePressed(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mouseReleased(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void keyPressed(KeyEvent e) {
              System.out.println(e.getKeyChar());
              textarea.append("The key " + e.getKeyChar()
                        + " click welcomes you to CO2001" + newline);
              textarea.setBackground(Color.YELLOW);
              textarea.setFont(new Font("Arial", Font.ITALIC, 16));
              textarea.setCaretPosition(textarea.getDocument().getLength());
         @Override
         public void keyReleased(KeyEvent e) {
              System.out.println(e.getKeyChar());
              // textarea.append("The key "+
              // e.getKeyChar()+" click welcomes you to CO2001" + newline);
              // textarea.setBackground(Color.green);
              // textarea.setCaretPosition(textarea.getDocument().getLength());
         @Override
         public void keyTyped(KeyEvent e) {
              // TODO Auto-generated method stub
              System.out.println(e.getKeyChar());
              // textarea.append("The key "+
              // e.getKeyChar()+" click welcomes you to CO2001" + newline);
              // textarea.setBackground(Color.blue);
              // textarea.setCaretPosition(textarea.getDocument().getLength());
         /** Returns an ImageIcon, or null if the path was invalid. */
         protected ImageIcon createImageIcon(String path, String description) {
              java.net.URL imgURL = getClass().getResource(path);
              if (imgURL != null) {
                   System.out.println("found");
                   return new ImageIcon(imgURL, description);
              } else {
                   System.err.println("Couldn't find file: " + path);
                   return null;
    }

    myJPanel.setPerferredSize(new Dimension(new_width, new_hight));
    myJFrame.pack();

  • Creating tables with a button click

    can anyone give me a sample code for creating multiple tables in a scrollpane
    with a button click.
    Thanks

    Here is an example that returns a JTable in a JScrollPane in a JInternalFrame:
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import java.awt.GridLayout;
    public class TablaJ extends JPanel{
         public TablaJ(){
         public TablaJ(String data[][], String columnNames[]){
             super(new GridLayout(1,0));
             final JTable table = new JTable(data, columnNames);
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            add(scrollPane);
        static JInternalFrame crearFrameConTabla(String data[][], String columnNames[], String tabla) {
            //Create and set up the window.
            JInternalFrame frame = new JInternalFrame(tabla,true,true,true,true);
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            //Create and set up the content pane.
            TablaJ newContentPane = new TablaJ(data, columnNames);
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);
            frame.pack();
            return frame;
    }

  • How to Figure out what checkboxes are selected upon a button click...

    If I have a panel with some JCheckBoxes and a JButton, how can I figure out what checkboxes are selected upon the button click? If I add an actionlistener to the button, inside actionPerformed, how would I know what checkboxes are selected? One caveat is that the name and number of these checkboxes are dymanically chaing based on a configuration file so I do not know what the names of these check boxes are.
    Any help/code sample would be appreciated.

    Here's one of several different ways to do it. It attaches an ItemListener to each checkBox. When the checkBox is clicked, it is either added or removed from a List of selected items. Clicking the button will show you the selected items.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class CheckBoxTest extends JFrame
      JCheckBox chkChoice1 = new JCheckBox("English");
      JCheckBox chkChoice2 = new JCheckBox("French");
      JCheckBox chkChoice3 = new JCheckBox("German");
      JCheckBox chkChoice4 = new JCheckBox("Italian");
      JTextArea txaDisplay = new JTextArea(5, 20);
      JButton btnShow = new JButton("Show Selected Items");
      ArrayList <JCheckBox>choices = new ArrayList<JCheckBox>();
      public CheckBoxTest()
        super("");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        chkChoice1.addItemListener(new CheckBoxListener(chkChoice1));
        chkChoice2.addItemListener(new CheckBoxListener(chkChoice2));
        chkChoice3.addItemListener(new CheckBoxListener(chkChoice3));
        chkChoice4.addItemListener(new CheckBoxListener(chkChoice4));
        btnShow.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent event)
            txaDisplay.setText("");
            for (JCheckBox jcb : choices)
              txaDisplay.append(jcb.getText() + "\n");
        JPanel buttonPanel = new JPanel(new FlowLayout());
        buttonPanel.add(chkChoice1);
        buttonPanel.add(chkChoice2);
        buttonPanel.add(chkChoice3);
        buttonPanel.add(chkChoice4);
        JScrollPane scroll = new JScrollPane(txaDisplay);
        scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        JPanel dataPanel = new JPanel();
        dataPanel.add(btnShow);
        dataPanel.add(scroll);
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        c.add(buttonPanel, BorderLayout.NORTH);
        c.add(dataPanel, BorderLayout.CENTER);
        pack();
      public static void main( String[] args )
        CheckBoxTest frame = new CheckBoxTest();
        frame.setVisible(true);
      class CheckBoxListener implements ItemListener
        JCheckBox checkBox;
        public CheckBoxListener(JCheckBox checkBox)
          this.checkBox = checkBox;
        public void itemStateChanged(ItemEvent event)
          if (checkBox.isSelected())
            choices.add(checkBox);
          else
            choices.remove(checkBox);
    }Or, you could just maintain all the checkboxes in a Collection ahead of time. When the Show button is selected, simple query isSelected() on each item.
    Again, there are several different ways.

  • Open a report from button click/javascript

    Hi,
    Does anyone know if there is a way to call a report from a button click? Or through javascript? I set the report to Display Results > Link - within the dashboard and then did a view source on it and found the function that calls the report from the hyperlink.
    This is the code:
    return DashboardReportLink('saw.dll?PortalGo&amp;_scid=v-x8QJloqTY&amp;PortalPath=/shared/Plan\x2520Setup\x2520Audit\x2520Tool\x2520/_portal/Plan\x2520Setup\x2520Audit&amp;Page=Historical&amp;NavFromViewID=d\x253adashboard\x257ep\x253acp4tq3p9brn77o6o\x257er\x253a8a2g9nltmkrtra9n&amp;Path=/shared/Plan\x2520Setup\x2520Audit\x2520Tool\x2520/Archive\x2520Reporting/Run\x2520Historical\x2520Report&amp;Action=PromptStart&amp;Options=frdc', 'd:dashboard~p:cp4tq3p9brn77o6o~r:8a2g9nltmkrtra9n','Dashboard&amp;PortalPath=/shared/Plan\x2520Setup\x2520Audit\x2520Tool\x2520/_portal/Plan\x2520Setup\x2520Audit&amp;Page=Historical', false)
    I added this function to the end of my javascript but when i click the button it just opens a blank page with
    http://la820119:9704/analytics/saw.dll?PortalGo
    as the url.
    Any help would be appreciated

    Hi,
    So i have been trying out a few things and the following url works to open the default view of the request:
    window.location='saw.dll?Go&Path=/shared/Plan Setup Audit Tool /Archive Reporting/Run Historical Report&Options=dfr';
    I just replaced 'Dashboard' in the code provided with the 'Go' and it started to work :)
    What i need to do though is have this work for the session variables set up on the dashboard. I have 7 prompts which a user can use to filter a request. Each is assigned to a session variable that is used to call a stored procedure. Originally i thought that by setting the variables and then calling the report from the url that the session variable values i set would be used in the request. What seems to be happening is that the variables get set and then, on calling the url, they are reset to the defaults and the report is run.
    Any help in solving this would be very much appreciated
    Una

  • How can I get a List ID information using JScript on ribbon button click - SharePoint2010

    Dear All,
    I want to display the custom list ID column information on ribbon button click using a JScript.
    For This I have added a JScript in Layout folder in VS 2010 empty project solution and I have put
    the following Jscript code. While running and clicking the ribbon button, it seems like JScript is not
    invoking and not producing any result. It is like control is not going to Jscript file. How can I find out
    the issue???? can anyone please help me on anything wrong with my script or is
    it some-other problem which causes the blank result???
    It is a farm sharepoint2010 solution, debugging is not working in Visual Studio & IE!!!!
    Somebody please help, hard to find the error.....
    Please note the JScript Code: RibAlert.js
    <script>
    '//var siteUrl = '/sites/MySiteCollection';
    var siteUrl = 'http://a5-12457/AllItems.aspx';
    function retrieveListItems()
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Custom List');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' +
    '<Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>10</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);
    clientContext.load(collListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    function onQuerySucceeded(sender, args)
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext())
    var oListItem = listItemEnumerator.get_current();
    listItemInfo += '\nID: ' + oListItem.get_id() +
    '\nTitle: ' + oListItem.get_item('Title') +
    '\nBody: ' + oListItem.get_item('Body');
    alert(listItemInfo.toString());
    function onQueryFailed(sender, args)
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    </script>
    Please note the Elements.xml
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
    Id="CustomRibbonButton"
    Location="CommandUI.Ribbon"
    RegistrationId="100"
    RegistrationType="List">
    <CommandUIExtension>
    <CommandUIDefinitions>
    <CommandUIDefinition
    Location="Ribbon.ListItem.Manage.Controls._children">
    <Button
    Id="Ribbon.ListItem.Manage.Controls.TestButton"
    Command="ShowAlert"
    Image16by16="http://a5-12457/IconLib/ICONBTN.jpg"
    Image32by32="http://a5-12457/IconLib/ICONBTN.jpg"
    LabelText="Comapre alert"
    TemplateAlias="o2"
    Sequence="501" />
    </CommandUIDefinition>
    </CommandUIDefinitions>
    <CommandUIHandlers>
    <!-- <CommandUIHandler Command="AboutButtonCommand" CommandAction="javascript:alert();" EnabledScript="javascript:enable();"/> -->
    <CommandUIHandler Command="ShowAlert" CommandAction="javascript:alert();" EnabledScript="return true;"/>
    </CommandUIHandlers>
    </CommandUIExtension>
    </CustomAction>
    <!-- <CustomAction Id="Ribbon.Library.Actions.Scripts" Location ="ScriptLink" ScriptSrc="/_layouts/DocumentTabTwo/RibButton.js" /> -->
    <CustomAction Id="Ribbon.Library.Actions.Scripts" Location ="ScriptLink" ScriptSrc="/_layouts/RibAlert.js" />
    </Elements>

    Dear All,
    I want to display the custom list ID column information on ribbon button click using a JScript.
    For This I have added a JScript in Layout folder in VS 2010 empty project solution and I have put
    the following Jscript code. While running and clicking the ribbon button, it seems like JScript is not
    invoking and not producing any result. It is like control is not going to Jscript file. How can I find out
    the issue???? can anyone please help me on anything wrong with my script or is
    it some-other problem which causes the blank result???
    It is a farm sharepoint2010 solution, debugging is not working in Visual Studio & IE!!!!
    Somebody please help, hard to find the error.....
    Please note the JScript Code: RibAlert.js
    <script>
    '//var siteUrl = '/sites/MySiteCollection';
    var siteUrl = 'http://a5-12457/AllItems.aspx';
    function retrieveListItems()
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Custom List');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' +
    '<Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>10</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);
    clientContext.load(collListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    function onQuerySucceeded(sender, args)
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext())
    var oListItem = listItemEnumerator.get_current();
    listItemInfo += '\nID: ' + oListItem.get_id() +
    '\nTitle: ' + oListItem.get_item('Title') +
    '\nBody: ' + oListItem.get_item('Body');
    alert(listItemInfo.toString());
    function onQueryFailed(sender, args)
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    </script>
    Please note the Elements.xml
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
    Id="CustomRibbonButton"
    Location="CommandUI.Ribbon"
    RegistrationId="100"
    RegistrationType="List">
    <CommandUIExtension>
    <CommandUIDefinitions>
    <CommandUIDefinition
    Location="Ribbon.ListItem.Manage.Controls._children">
    <Button
    Id="Ribbon.ListItem.Manage.Controls.TestButton"
    Command="ShowAlert"
    Image16by16="http://a5-12457/IconLib/ICONBTN.jpg"
    Image32by32="http://a5-12457/IconLib/ICONBTN.jpg"
    LabelText="Comapre alert"
    TemplateAlias="o2"
    Sequence="501" />
    </CommandUIDefinition>
    </CommandUIDefinitions>
    <CommandUIHandlers>
    <!-- <CommandUIHandler Command="AboutButtonCommand" CommandAction="javascript:alert();" EnabledScript="javascript:enable();"/> -->
    <CommandUIHandler Command="ShowAlert" CommandAction="javascript:alert();" EnabledScript="return true;"/>
    </CommandUIHandlers>
    </CommandUIExtension>
    </CustomAction>
    <!-- <CustomAction Id="Ribbon.Library.Actions.Scripts" Location ="ScriptLink" ScriptSrc="/_layouts/DocumentTabTwo/RibButton.js" /> -->
    <CustomAction Id="Ribbon.Library.Actions.Scripts" Location ="ScriptLink" ScriptSrc="/_layouts/RibAlert.js" />
    </Elements>

  • CRM5.2 UI-Call a dynamic URL on button click

    Hi all, 
               My requirement is to call a dynamic url on the click of a button in the overview page. I have added a custom button in  the method  IF_BSP_WD_TOOLBAR_CALLBACK~GET_BUTTONS , and the related code in do_handle_event.I have created a custom method for the button event. I have enhanced a custom controller and created an attribute.In the custom method created for the button event, I have written the code for retrieving the parameters to be passed to the url.
    In the layout of the view associated with the display view , I have written the following code for calling the URL in a new window.
    <%
    DATA: lr_cuco_EMA TYPE REF TO ZL_BP_CONT_BPCONT_IMPL,
          lv_url TYPE string,
          lv_url1 type string,
          lv_count type i.
      lr_cuco_EMA ?= controller->get_custom_controller( 'ZBP_CONT/BPCONT' ).
      check lr_cuco_EMA is bound.
      if lr_cuco_EMA->gv_VALUE is not initial.
      if lr_cuco_EMA->gv_COUNT IS NOT INITIAL.
      clear lr_cuco_EMA->gv_COUNT.
      endif.
      LV_URL = lr_cuco_EMA->gv_VALUE.
      Concatenate 'http:/' LV_URL  into LV_URL1.
      Concatenate '"http:/' LV_URL '"' into LV_URL.
        lv_count = lr_cuco_EMA->gv_COUNT mod '2'.
        if lv_count Ne 0.
      lv_url = lv_url1.
    endif.
      %>
         <scrpt language="Javascript">
            window.open(<%= lv_url%>).focus();
          </script>
       <%
             lr_cuco_EMA->gv_COUNT = lr_cuco_EMA->gv_COUNT + 1.
             clear lr_cuco_EMA->gv_value.
             clear lv_count.
             clear lv_url.
             clear lv_url1.
             ENDIF.
    %>
    But here my URl is getting called alternate times.If I do not write the code  by using the variable GV_COUNT the url is getting called only the first time of the button click  and to call the URL again you need to navigate back to the search page and again back to the overview page and click on the button.
    Can anyone help me regarding this? I want the URL to be called in a new page on every button click.
    Thanks in Advance,
    Chandana

    Hi Nisha,
    The crux of your issue here is that you want to call the event triggered with onClick before calling the event triggered on onClientClick. This can be achieved by the following code in the function called on the onClientClick.
    function fn_button()
               htmlbSL(this,2,'b_row_selection:onInputProcessing()');
               window.open("new_page",target="BLANK");
    Here, fn_button is the javascript function called on button click, and b_row_selection is the event triggered on the onClick event of row selection.
    Try this out and let us know if it works for you.
    Regards,
    Saurabh

  • Clearing array on button click

    i have a problem in clearing array.
    1. i have a vi witch on a button click add element in array ,and plot the values on graph.
    2. second time when i run vi on graph i get all the values witch i got in first run pluse the values on second run
    2. i want my graph should not plot values i got in first run
    3. if I initialise the shift reg.then at every button click it plots only one point on graph.
    4. I want all the points witch I added in my array at second run
    so please help me
    Shital"

    Ok, so we have an XY graph. Here I've attached two examples of the same approach as earlier (just second one use only one array of x-y pairs to store data). Local variables used only for cleaning graph display BEFORE any new points will be added (after first point you add, it will be also initialized). So this is just for cosmetic reasons
    Attachments:
    Shift_register_array_initialization1.vi ‏46 KB
    Shift_register_array_initialization2.vi ‏43 KB

Maybe you are looking for