0

I am implementing a search interface in eclipse with the help of mysql. My search interface yields the results I want, but I want to be able to have the "video_url" column clickable and bring up a hyperlink. Is there a way to do this for a single column? Right now the Jtable is "editable", so the user can click on it, but no changes are made to it. The link can be copied and then pasted later, but I'm really trying to have the link be opened from the interface.

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    VIdeo_search_test window = new VIdeo_search_test();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public VIdeo_search_test() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 17));
        frame.setBounds(400, 400, 1050, 1000);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);

        JLabel lblVideoSearch = new JLabel("Video Search");
        lblVideoSearch.setFont(new Font("Tahoma", Font.PLAIN, 19));
        lblVideoSearch.setBounds(241, 11, 230, 27);
        frame.getContentPane().add(lblVideoSearch);

        JButton btnSearchCity = new JButton("Search City");
        btnSearchCity.setBounds(216, 80, 165, 25);
        btnSearchCity.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {


                DefaultTableModel model = new DefaultTableModel(new String[]{"video_url", "video name", "video description", "video_city", "video_subject", "video_tags", "reviewed_by", "star"}, 0);


try {

                    Class.forName("com.mysql.cj.jdbc.Driver");
                    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/userdatabase", "root", "pass1234");

                    Statement stmt= con.createStatement();
                    String sql = "Select * from video where video_city = '" +txtCity.getText()+"'";
                    ResultSet rs=stmt.executeQuery(sql);
                    while(rs.next())
                    {
                         String a = rs.getString("video_url");
                         String d = rs.getString("video_name");
                         String e = rs.getString("video_description");
                         String f = rs.getString("video_city");
                         String g = rs.getString("video_subject");
                         String h = rs.getString("video_tags");
                         String k = rs.getString("reviewed_by");
                         String i = rs.getString("star");
                         model.addRow(new Object[]{a, d, e, f, g, h, k, i});

                            table.setModel(model);

                              }
                                {

                               con.close();}
                    } catch(Exception e) {System.out.print (e);}

            }
        });
        frame.getContentPane().add(btnSearchCity);

        JButton btnSearchTag = new JButton("Search Tag");
        btnSearchTag.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                DefaultTableModel model = new DefaultTableModel(new String[]{"video_url", "video name", "video description", "video_city", "video_subject", "video_tags", "reviewed_by", "star"}, 0);


                try {

                                    Class.forName("com.mysql.cj.jdbc.Driver");
                                    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/userdatabase", "root", "pass1234");

                                    Statement stmt= con.createStatement();
                                    String sql = "Select * from video where video_tags LIKE '"+txtTag.getText()+"%'";
                                    ResultSet rs=stmt.executeQuery(sql);
                                    while(rs.next())
                                    {
                                                String a = rs.getString("video_url");
                                                String d = rs.getString("video_name");
                                                String e = rs.getString("video_description");
                                                String f = rs.getString("video_city");
                                                String g = rs.getString("video_subject");
                                                String h = rs.getString("video_tags");
                                                String k = rs.getString("reviewed_by");
                                                String i = rs.getString("star");
                                                model.addRow(new Object[]{a, d, e, f, g, h, k, i});

                                            table_1.setModel(model);

                                              }
                                    {                                       


                                               con.close();}
                                    } catch(Exception e) {System.out.print (e);}

                            }



        });
        btnSearchTag.setBounds(216, 303, 165, 25);
        frame.getContentPane().add(btnSearchTag);

        txtCity = new JTextField();
        txtCity.setBounds(216, 49, 165, 20);
        frame.getContentPane().add(txtCity);
        txtCity.setColumns(10);

        table = new JTable();
        table.setBounds(10, 116, 867, 135);
        frame.getContentPane().add(table);

        txtTag = new JTextField();
        txtTag.setColumns(10);
        txtTag.setBounds(216, 272, 165, 20);
        frame.getContentPane().add(txtTag);

        table_1 = new JTable();
        table_1.setBounds(10, 341, 601, 135);
        frame.getContentPane().add(table_1);

        JButton btnViewVideo = new JButton("View Video");
        btnViewVideo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {

                registered_video_interface info = new registered_video_interface();
                registered_video_interface.main(null); }


        });
        btnViewVideo.setBounds(251, 509, 89, 23);
        frame.getContentPane().add(btnViewVideo);
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Tengu
  • 67
  • 1
  • 8
  • [Here](https://stackoverflow.com/questions/4256680/click-hyperlink-in-jtable) you can find one example. It doesn't provide rollover support, but links are clickable. Rollover support is also possible, but I have no time to remove all dependencies to 3rd party libs from my code ;). – Sergiy Medvynskyy Dec 02 '19 at 07:30
  • 2
    1) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! Most IDEs have a keyboard shortcut specifically for formatting code. 3) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. .. – Andrew Thompson Dec 02 '19 at 08:15
  • 2
    .. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Dec 02 '19 at 08:15

0 Answers0