Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: TextFieldWithButton

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    25
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default TextFieldWithButton

    Hello
    I'm trying to add JButton into JTextField like in the image below is it possible or not
    and is it possible to do like that in JTable cell

    thanks
    Last edited by serdar; August 27th, 2011 at 01:18 AM.

  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: TextFieldWithButton

    Since a textfield is for text I'm sure you cannot add a button to it. Why would you want to do that anyway? Why can't you place the button next to the textfield?
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: TextFieldWithButton

    the image you're give is in your computer we can't see it.

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    25
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: TextFieldWithButton

    Quote Originally Posted by Junky View Post
    Since a textfield is for text I'm sure you cannot add a button to it.
    after posting this thread I asked this question to my other friends and one of them told that it is possible by add() method
    I tried it and it works
    import java.awt.*;
      import javax.swing.*;
     
    public class ButtonInTextField extends JFrame
    {
        JTextField tekst;
        JButton knopka;
        Container c;
     
        public ButtonInTextField()
        {
         c = getContentPane();
         c.setLayout(new FlowLayout());
     
         tekst = new JTextField (10);
         knopka = new JButton("");
         //tekst.setHorizontalAlignment(15);
         //tekst.setLayout(new FlowLayout());
         tekst.setLayout(new BorderLayout());
         tekst.add(knopka,BorderLayout.EAST);
     
         c.add(tekst);
     
         setSize( 300, 200 );
         setVisible( true );
        }
     
        public static void main( String args[] )
         {
            ButtonInTextField rustiX = new ButtonInTextField();
            rustiX.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
         }
    }
    so I think this will helpful to you too
    Quote Originally Posted by Junky View Post
    Why would you want to do that anyway? Why can't you place the button next to the textfield?
    I wanted to do something like JComboBox

  5. #5
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: TextFieldWithButton

    wow that is weirddddd but cool lol it does kinda look like a combobox