Example usage for javax.swing JScrollPane add

List of usage examples for javax.swing JScrollPane add

Introduction

In this page you can find the example usage for javax.swing JScrollPane add.

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:views.SentimentGraph.java

public SentimentGraph(String applicationTitle, String chartTitle) throws ParseException {
    super(applicationTitle);
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Date", "Polarity", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1000, 367));
    JScrollPane pane = new JScrollPane();
    pane.add(chartPanel);
    setContentPane(chartPanel);/* ww w .  jav  a  2  s.c  o  m*/

}

From source file:views.StockGraph.java

public StockGraph(String FrameTitle, String chartTitle) {
    super(FrameTitle);
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Date", "Price", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1000, 367));
    JScrollPane pane = new JScrollPane();
    pane.add(chartPanel);
    setContentPane(chartPanel);/*w  ww . java2s  . c  om*/

}

From source file:Main_Window.java

public void Send_Receive_Data_Google_Service(boolean State) {
    try {/*  www.j  av a2  s. c  o  m*/
        ServerAddress = new URL("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="
                + Double.parseDouble(Latitude_TextField.getText()) + ","
                + Double.parseDouble(Longitude_TextField.getText()) + "&radius="
                + Double.parseDouble(Radius_TextField.getText()) + "&opennow=" + Boolean.toString(State)
                + "&types=" + Categories.getSelectedItem().toString() + "&key=" + API_KEY);
        //DELTE
        String str = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="
                + Double.parseDouble(Latitude_TextField.getText()) + ","
                + Double.parseDouble(Longitude_TextField.getText()) + "&radius="
                + Double.parseDouble(Radius_TextField.getText()) + "&opennow=" + Boolean.toString(State)
                + "&types=" + Categories.getSelectedItem().toString() + "&key=" + API_KEY;
        System.out.println(" To url einai -> " + str);
        //set up out communications stuff
        Connection = null;
        //Set up the initial connection
        Connection = (HttpURLConnection) ServerAddress.openConnection();
        Connection.setRequestMethod("GET");
        Connection.setDoOutput(true); //Set the DoOutput flag to true if you intend to use the URL connection for output
        Connection.setDoInput(true);
        Connection.setRequestProperty("Content-type", "text/xml"); //Sets the general request property
        Connection.setAllowUserInteraction(false);
        Encode_String = URLEncoder.encode("test", "UTF-8");
        Connection.setRequestProperty("Content-length", "" + Encode_String.length());
        Connection.setReadTimeout(10000);
        // A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. 
        //If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. 
    } catch (IOException IOE) {
        JOptionPane.showMessageDialog(null, "Error -> " + IOE.getLocalizedMessage(), "Exception - IOException",
                JOptionPane.ERROR_MESSAGE, null);
    }

    try {
        wr = new DataOutputStream(Connection.getOutputStream());
        //open output stream to write
    } catch (IOException IOE) {
        JOptionPane.showMessageDialog(null, "Error -> " + IOE.getLocalizedMessage(), "Exception - IOException",
                JOptionPane.ERROR_MESSAGE, null);
    }

    try {
        wr.writeBytes("q=" + strData);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException",
                JOptionPane.ERROR_MESSAGE, null);
    }

    try {
        wr.flush();
        //Force all data to write in channel
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException",
                JOptionPane.ERROR_MESSAGE, null);
    }

    try {
        //read the result from the server
        Buffered_Reader = new BufferedReader(new InputStreamReader(Connection.getInputStream()));
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException",
                JOptionPane.ERROR_MESSAGE, null);
    }

    jsonParser = new JSONParser(); //JSON Parser

    try {
        JsonObject = (JSONObject) jsonParser.parse(Buffered_Reader); //Parse whole BuffererReader IN Object
        JSONArray Results_Array_Json = (JSONArray) JsonObject.get("results"); //take whole array - from json format
        //results - is as string unique that contains all the essential information such as arrays, and strings. So to extract all info we extract results into JSONarray
        //And this comes up due to json format
        for (int i = 0; i < Results_Array_Json.size(); i++) // Loop over each each part of array that contains info we must extract
        {
            JSONObject o = (JSONObject) Results_Array_Json.get(i);

            try { //We assume that for every POI exists for sure an address !!! thats why the code is not insida a try-catch
                Temp_Name = (String) o.get("name");
                Temp_Address = (String) o.get("vicinity");
                JSONObject Str_1 = (JSONObject) o.get("geometry"); //Geometry is object so extract geometry
                JSONArray Photo_1 = (JSONArray) o.get("photos");
                JSONObject Photo_2 = (JSONObject) Photo_1.get(0);
                String Photo_Ref = (String) Photo_2.get("photo_reference");
                JSONObject Str_2 = (JSONObject) Str_1.get("location");
                Temp_X = (double) Str_2.get("lat");
                Temp_Y = (double) Str_2.get("lng");
                //In case some POI has no Rating
                try {
                    //Inside try-catch block because may some POI has no rating
                    Temp_Rating = (double) o.get("rating");
                    Point POI_Object = new Point(Temp_Name, Temp_Address, Photo_Ref, Temp_Rating, Temp_X,
                            Temp_Y);
                    POI_List.add(POI_Object); //Add POI in List to keep it
                } catch (Exception Er) {
                    //JOptionPane.showMessageDialog ( null, "No rating for this POI " ) ;
                    Point POI_Object_2 = new Point(Temp_Name, Temp_Address, Photo_Ref, 0.0, Temp_X, Temp_Y);
                    POI_List.add(POI_Object_2); //Add POI in List to keep it
                }
            } catch (Exception E) {
                //JOptionPane.showMessageDialog ( this, "Error -> " + E.getLocalizedMessage ( ) + ", " + E.getMessage ( ) ) ;
            }
            o.clear();
        }
    } catch (ParseException PE) {
        JOptionPane.showMessageDialog(this, "Error -> " + PE.getLocalizedMessage(),
                "Parse, inside while JSON ERROR", JOptionPane.ERROR_MESSAGE, null);
    } catch (IOException IOE) {
        JOptionPane.showMessageDialog(this, "Error -> " + IOE.getLocalizedMessage(), "IOExcpiton",
                JOptionPane.ERROR_MESSAGE, null);
    }

    if (POI_List.isEmpty()) {
        JOptionPane.showMessageDialog(this, "No Results");
    } else {
        //Calculate Distance every POI from Longitude and latitude of User

        for (int k = 0; k < POI_List.size(); k++) {
            double D1 = Double.parseDouble(Latitude_TextField.getText()) - POI_List.get(k).Get_Distance_X();
            double D2 = Double.parseDouble(Longitude_TextField.getText()) - POI_List.get(k).Get_Distance_Y();
            double a = pow(sin(D1 / 2), 2) + cos(POI_List.get(k).Get_Distance_X())
                    * cos(Double.parseDouble(Latitude_TextField.getText())) * pow(sin(D2 / 2), 2);
            double c = 2 * atan2(sqrt(a), sqrt(1 - a));
            double d = 70000 * c; // (where R is the radius of the Earth)  in meters
            //add to list
            Distances_List.add(d);
        }

        //COPY array because Distances_List will be corrupted
        for (int g = 0; g < Distances_List.size(); g++) {
            Distances_List_2.add(Distances_List.get(g));
        }

        for (int l = 0; l < Distances_List.size(); l++) {
            int Dou = Distances_List.indexOf(Collections.min(Distances_List)); //Take the min , but the result is the position that the min is been placed
            Number_Name N = new Number_Name(POI_List.get(Dou).Get_Name()); //Create an object  with the name of POI in the min position in the POI_List
            Temp_List.add(N);
            Distances_List.set(Dou, 9999.99); //Make the number in the min position so large so be able to find the next min
        }
        String[] T = new String[Temp_List.size()]; //String array to holds all names of POIS that are going to be dispayled in ascending order
        //DISPLAY POI IN JLIST - Create String Array with Names in ascending order to create JList
        for (int h = 0; h < Temp_List.size(); h++) {
            T[h] = Temp_List.get(h).Get_Name();
        }
        //System.out.println ( " Size T -> " + T.length ) ;
        //Make JList and put String names 
        list = new JList(T);
        list.setForeground(Color.BLACK);
        list.setBackground(Color.GRAY);
        list.setBounds(550, 140, 400, 400);
        //list.setSelectionMode ( ListSelectionModel.SINGLE_SELECTION ) ;
        JScrollPane p = new JScrollPane(list);
        P.add(p);
        setContentPane(pane);
        //OK
        list.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent event) {
                String selected = list.getSelectedValue().toString();
                System.out.println("Selected string" + selected);
                for (int n = 0; n < POI_List.size(); n++) {
                    if (selected.equals(POI_List.get(n).Get_Name())) {
                        try {
                            //read the result from the server
                            BufferedImage img = null;
                            URL u = new URL(
                                    "https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference="
                                            + POI_List.get(n).Get_Photo_Ref() + "&key=" + API_KEY);
                            Image image = ImageIO.read(u);
                            IMAGE_LABEL.setText("");
                            IMAGE_LABEL.setIcon(new ImageIcon(image));
                            IMAGE_LABEL.setBounds(550, 310, 500, 200); //SOSOSOSOSOS
                            pane.add(IMAGE_LABEL);
                        } catch (IOException ex) {
                            JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(),
                                    "Exception - IOException", JOptionPane.ERROR_MESSAGE, null);
                        }

                        Distance_L.setBounds(550, 460, 350, 150);
                        Distance_L.setText("");
                        Distance_L.setText(
                                "Distance from the current location: " + Distances_List_2.get(n) + "m");
                        pane.add(Distance_L);

                        Address_L.setBounds(550, 500, 350, 150);
                        Address_L.setText("");
                        Address_L.setText("Address: " + POI_List.get(n).Get_Address());
                        pane.add(Address_L);

                        Rating_L.setBounds(550, 540, 350, 150);
                        Rating_L.setText("");
                        Rating_L.setText("Rating: " + POI_List.get(n).Get_Rating());
                        pane.add(Rating_L);
                    }
                }
            }
        });
    } //Else not empty
}

From source file:gdt.jgui.tool.JEntityEditor.java

private void showElement(Sack entity, String element$) {
    try {//from w w  w.ja va  2s  .  c om
        //      System.out.println("EntityEditor:showElement:"+element$);
        Core[] ca = null;
        if ("attributes".equals(element$))
            ca = entity.attributesGet();
        else
            ca = entity.elementGet(element$);
        final JTable table = new JTable();
        DefaultTableModel model = new DefaultTableModel(null, new String[] { "type", "name", "value" });
        table.setModel(model);
        table.getTableHeader().setDefaultRenderer(new SimpleHeaderRenderer());
        table.getTableHeader().addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                int col = table.columnAtPoint(e.getPoint());
                String name = table.getColumnName(col);
                //              System.out.println("Column index selected " + col + " " + name);
                sort(name);
            }
        });
        JScrollPane scrollPane = new JScrollPane();
        tabbedPane.add(element$, scrollPane);
        scrollPane.add(table);
        scrollPane.setViewportView(table);
        if (ca != null)
            for (Core aCa : ca) {
                model.addRow(new String[] { aCa.type, aCa.name, aCa.value });
            }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:com.view.TradeWindow.java

private void TraderBlockOrdersActionPerformed(java.awt.event.ActionEvent evt) {
    TableModel dtm = (TableModel) TraderIncomingRequestsTable.getModel();
    int nRow = dtm.getRowCount();
    int nCol = dtm.getColumnCount();
    Object[][] tableData = new Object[nRow][nCol];
    ArrayList<SingleOrder> parsedOrders = new ArrayList();
    ControllerBlockOrders control = new ControllerBlockOrders();

    for (int i = 0; i < nRow; i++) {
        for (int j = 0; j < nCol; j++) {
            tableData[i][j] = dtm.getValueAt(i, j);
        }/*from  w  w w  .j a  va 2  s. c  o m*/
        SingleOrder o = new SingleOrder();
        o.SingleOrderMakeBlocks(tableData[i]);
        parsedOrders.add(o);
    }
    singleOrderLists = control.MakeBlock(parsedOrders);
    showMessageDialog(null, "Blocks have been successfully completed.");
    //dtm.setRowCount(0);
    TraderPlatformBlockedRequests.setLayout(new BorderLayout());
    int count = 1;
    ArrayList<JScrollPane> paneList = new ArrayList<JScrollPane>();
    for (ArrayList<SingleOrder> b : singleOrderLists) {
        JTable jTable = new JTable();
        jTable.setModel(CTraderBlockOrder.getTableModel(b));
        Dimension d = jTable.getPreferredSize();
        // System.out.println(d);
        int rows = jTable.getRowCount();
        // System.out.println(rows);
        JScrollPane jPane = new JScrollPane();
        jPane.setPreferredSize(new Dimension(d.width, jTable.getRowHeight() * rows + 50));
        jPane.add(jTable);
        jPane.setViewportView(jTable);
        paneList.add(jPane);
        count++;
    }

    test.add(blockOptions);
    int i = 0;
    for (final JScrollPane j : paneList) {
        //   JButton btn = new JButton();
        //  btn.setText("Split Block");
        //     btn.setName(""+i);

        JPanel cPanel = new JPanel();
        /*  btn.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            JViewport viewport = j.getViewport(); 
            final JTable mytable = (JTable)viewport.getView();
            final ArrayList<Integer> index = new ArrayList<Integer>();
            for(int row = 0;row<mytable.getRowCount();row++){
                  if((boolean)mytable.getValueAt(row, 11)){
                     index.add(row);
                  }
            }
             SplitBlockActionPerformed(evt,index,cPanel,test);
         }
          });*/
        JCheckBox check = new JCheckBox();
        JLabel label = new JLabel();
        label.setText("Select Block");
        check.setName("" + i);
        check.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SelectBlockActionPerformed(evt);
            }
        });
        JPanel splitOptions = new JPanel();
        splitOptions.add(label);
        splitOptions.add(check);
        splitOptions.setName("splitOpt");
        //  splitOptions.add(btn);
        cPanel.setName("cPanel" + i);
        cPanel.add(splitOptions);
        cPanel.add(j);
        cPanel.setLayout(new BoxLayout(cPanel, BoxLayout.Y_AXIS));
        test.add(cPanel);
        cPanelList.add(cPanel);
        i++;
    }

    test.setLayout(new BoxLayout(test, BoxLayout.Y_AXIS));
    JScrollPane p = new JScrollPane(test);
    p.setName("ParentP");
    TraderPlatformBlockedRequests.add(p);
    TraderPlatformBlockedRequests.validate();
    TraderPlatformTabbedPane.setSelectedIndex(TraderPlatformTabbedPane.getSelectedIndex() + 1);

}