Page 1 of 2 12 LastLast
Results 1 to 20 of 25
  1. #1
    AngeloGilio is offline Member
    Join Date
    Mar 2015
    Posts
    11
    Rep Power
    0

    Default Using JtextField as gogole toolbar

    Anyone knows how build a Google toolbar to search on web with java? I have this code but somthing is wrong...please help!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Using JtextField as gogole toolbar

    Quote Originally Posted by AngeloGilio View Post
    Anyone knows how build a Google toolbar to search on web with java? I have this code but somthing is wrong...please help!
    What code?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    AngeloGilio is offline Member
    Join Date
    Mar 2015
    Posts
    11
    Rep Power
    0

    Default Re: Using JtextField as gogole toolbar

    i used this code in netbeans mudule and works..i'm not able to use this code in swing form...may you know how make it works?:::

    private void jTextField1ActionPerformed(java.awt.event.ActionEv ent evt) {
    try {
    String searchText = URLEncoder.encode(jTextField1.getText(), "UTF-8");
    URLDisplayer.getDefault().showURL
    (new URL("http://www.google.com/search?hl=en&q="+searchText+"&btnG=Google+Search") );
    } catch (Exception eee){
    return;

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Using JtextField as gogole toolbar

    That is no wonder since URLDisplayer is a class that is not part of the standard JDK, it is part of the Netbeans platform.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    AngeloGilio is offline Member
    Join Date
    Mar 2015
    Posts
    11
    Rep Power
    0

    Default Re: Using JtextField as gogole toolbar

    what should i use..?

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Using JtextField as gogole toolbar

    I don't really know. Your question is not really specifically about showing a Google search box, its about displaying a webpage which in your case just happens to be the Google search website. You'd have to google for ways to do that though Swing.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    AngeloGilio is offline Member
    Join Date
    Mar 2015
    Posts
    11
    Rep Power
    0

    Default Re: Using JtextField as gogole toolbar

    So..i can remake my question...how to serch on web by keywords..i know how build a browser but i would like searching on web by keyword end than open a webpage...i'm not really set gogole as default browser.
    Thanks!

  8. #8
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Using JtextField as gogole toolbar

    Quote Originally Posted by AngeloGilio View Post
    i know how build a browser
    Do you? What do you mean by that? Like, you've build something that resembles, say, Firefox?

    If you want this to run in the user's browser, you could let the JRE handle it itself

    Java Code:
    Desktop.getDesktop().browse(URI);
    If this needs to be Swing, an option is JTextPane.setPage(String)

    Desktop (Java Platform SE 8)
    JEditorPane (Java Platform SE 8 )
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  9. #9
    AngeloGilio is offline Member
    Join Date
    Mar 2015
    Posts
    11
    Rep Power
    0

    Default Re: Using JtextField as gogole toolbar

    Thanks anyway SurfMan but it not i'm looking for...

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Using JtextField as gogole toolbar

    But that is exactly what you ask, so then you're asking about things you don't actually want.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    AngeloGilio is offline Member
    Join Date
    Mar 2015
    Posts
    11
    Rep Power
    0

    Default Re: Using JtextField as gogole toolbar

    So...I'm looking for how make a reseach on web using a JtextText ..i want to put a keyword for example: DOG, clicking a Jbutton it will open the default browser who show me the results that i searched.

    Pratically instead of searching on Google i wont using my on Swing form...That what i wuold liket to do.. is it clear know? I find i way but using Netbeans Module but the same code( i posted up) but it doens't wok in a normal Swing class

  12. #12
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Using JtextField as gogole toolbar

    Quote Originally Posted by AngeloGilio View Post
    So...I'm looking for how make a reseach on web using a JtextText ..i want to put a keyword for example: DOG, clicking a Jbutton it will open the default browser who show me the results that i searched.

    Pratically instead of searching on Google i wont using my on Swing form...That what i wuold liket to do.. is it clear know? I find i way but using Netbeans Module but the same code( i posted up) but it doens't wok in a normal Swing class
    That is exactly what I gave you:
    Java Code:
    Desktop.getDesktop().browse("http://www.google.com/#q=DOG");
    Edit: I would think replacing URLDisplayer.getDefault().showURL() with the above would simply do the trick.
    Last edited by SurfMan; 03-05-2015 at 04:27 PM.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  13. #13
    AngeloGilio is offline Member
    Join Date
    Mar 2015
    Posts
    11
    Rep Power
    0

    Default Re: Using JtextField as gogole toolbar

    Do you mean like this?...

    package googlesearch;

    import java.awt.Desktop;

    import java.net.URLEncoder;

    public class GoogleForm extends javax.swing.JFrame {

    public GoogleForm() {
    initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    jTextField1 = new javax.swing.JTextField();
    Search = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextPane1 = new javax.swing.JTextPane();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

    jTextField1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jTextField1ActionPerformed(evt);
    }
    });

    Search.setText("Search");
    Search.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    SearchActionPerformed(evt);
    }
    });

    jScrollPane1.setViewportView(jTextPane1);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(jScrollPane1)
    .addGroup(layout.createSequentialGroup()
    .addComponent(Search)
    .addGap(18, 18, 18)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(0, 0, Short.MAX_VALUE)))
    .addContainerGap())
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(40, 40, 40)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(Search))
    .addGap(68, 68, 68)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(94, Short.MAX_VALUE))
    );

    pack();
    }// </editor-fold>

    private void SearchActionPerformed(java.awt.event.ActionEvent evt) {

    }

    private void jTextField1ActionPerformed(java.awt.event.ActionEv ent evt) {

    try {
    String searchText = URLEncoder.encode(jTextField1.getText(), "UTF-8");
    Desktop.getDesktop().browse("http://www.google.com/#q=" + searchText);

    } catch (Exception eee) {
    return;//nothing much to do

    }

    //public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new GoogleForm().setVisible(true);
    }
    });
    }

    // Variables declaration - do not modify
    private javax.swing.JButton Search;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration

  14. #14
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Using JtextField as gogole toolbar

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  15. #15
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Using JtextField as gogole toolbar

    Quote Originally Posted by AngeloGilio View Post
    Do you mean like this?...
    Does it work?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  16. #16
    AngeloGilio is offline Member
    Join Date
    Mar 2015
    Posts
    11
    Rep Power
    0

    Default Re: Using JtextField as gogole toolbar

    No Man! Unfortunately...

  17. #17
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Using JtextField as gogole toolbar

    It shouldn't even compile since the API documentation states the browse() method requires an URI rather than a String parameter:

    Desktop (Java Platform SE 8 )
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  18. #18
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Using JtextField as gogole toolbar

    Quote Originally Posted by gimbal2 View Post
    It shouldn't even compile since the API documentation states the browse() method requires an URI rather than a String parameter:
    I gave the correct URI example in reply #8 but a wrong String example in reply #12. Bad SurfMan! I won't be mad at you for blaming me. After all, who reads the compiler messages!?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  19. #19
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Using JtextField as gogole toolbar

    Quote Originally Posted by SurfMan View Post
    I gave the correct URI example in reply #8 but a wrong String example in reply #12. Bad SurfMan! I won't be mad at you for blaming me. After all, who reads the compiler messages!?
    Or the API documentation when said compiler barfs up a compile error.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  20. #20
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Using JtextField as gogole toolbar

    Quote Originally Posted by SurfMan View Post
    After all, who reads the compiler messages!?
    <sticks finger up in the air>
    Erm, I do ...
    </sticks finger up in the air>

    But my old mum already told everyone that I was a strange kid ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 07-17-2014, 02:27 PM
  2. Replies: 3
    Last Post: 11-14-2011, 05:13 AM
  3. Replies: 1
    Last Post: 01-30-2009, 06:44 PM
  4. Creating a toolbar in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 08:08 PM
  5. How to use ToolBar in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 08:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •