Results 1 to 12 of 12
  1. #1
    Arr
    Arr is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Gui text problem

    Hey guys. I am trying to find something about my problem for like two hours but without any success. I am beginner and I just cant handle this problem. I got button down there(flowlayout) and I need to get locked text field with a text to center, above the button I mean. I have tried to use JAreatext or Textfield and nothing work how I need to. I dont know if its because I am beginner or these are not good ones.
    This is what I mean.


    If you will need any code or something, tell me.
    Thanks for help.


    PS: I got plenty of questions, so maybe I will write them there.
    1) How to add texture to background of that gui?
    2) Can I somehow change button color or add a texture? I got there a ImageIcon but its not across whole button.
    Last edited by Arr; 04-23-2012 at 06:00 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Gui text problem

    Moved from New to Java.

    Quote Originally Posted by Arr View Post
    I got button down there(flowlayout) and I need to get locked text field with a text to center, above the button I mean.
    Choose a suitable layout manager.
    Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    Quote Originally Posted by Arr View Post
    If you will need any code or something, tell me.
    To get better help sooner, always post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem, but only after researching and trying out stuff yourself.

    Quote Originally Posted by Arr View Post
    1) How to add texture to background of that gui?
    Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    TexturePaint (Java Platform SE 6)

    Note that every Graphics instance is a Graphics2D and can be cast to use the methods of Graphics2D

    Quote Originally Posted by Arr View Post
    2) Can I somehow change button color or add a texture? I got there a ImageIcon but its not across whole button.
    More custom painting.

    But, seriously, learn to walk before you try to run.

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

  3. #3
    Arr
    Arr is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: Gui text problem

    Yeah, i want to learn to walk before I try to run, but its a school project annouced like four days ago and I dont have too much time to complete it.


    I tried JLabel, but there is one problem. It cant do newline with escape sequence. So Its looks like I will need try something else.

    label1 = new JLabel("Image and Textkmsmk\n sdfsdf",JLabel.CENTER);
    label1.setVerticalTextPosition(JLabel.BOTTOM);
    label1.setHorizontalTextPosition(JLabel.CENTER);
    add(label1);
    ----
    I tried this one too, but the escape sequence still doenst work, I just dont know why.
    abc = new JTextField("Image and Textkmsmk\n sdfsdf");
    abc.setEditable(false);
    add(abc);

    I dont tried graphics yet, but today in school teacher showed me and It works pretty good.

    --
    So JLabel and JTextField are all only for one line? What should I used then? I tried JList too, but Its looks awful.
    Last edited by Arr; 04-25-2012 at 11:33 PM.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Gui text problem

    JLabel can display HTML with <br> tags in multiple lines.

    JTextField is always single lined.

    JTextArea is multiline and recognizes the newline escape sequence.

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

  5. #5
    lalu is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Gui text problem

    you can use null layout and simply set the coordinate of label that u want to be appear while pressing cancel button.
    if u want 2 use flow layout than u can use netbeans software were u can simply drag and drop ur items.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Gui text problem

    Quote Originally Posted by lalu View Post
    you can use null layout and simply set the coordinate of label that u want to be appear while pressing cancel button.
    if u want 2 use flow layout than u can use netbeans software were u can simply drag and drop ur items.
    Both extremely bad advice. Even worse than the spelling capabilities of the person who posted them.

    Avoid null layout, in the long run it causes more problems than it seems to solve. In any case, you'll need to understand layout managers, so why postpone it?

    And the NetBeans visual designer is categorically not a beginners' tool. Without an understanding of Swing coding, you'll get lost trying to discover how to use it effectively. hand coding a Swing GUI is much easier by comparison; it's only worth putting effort into learning the quirks of the visual designer if you intend to make a living designing Swing GUIs.

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

  7. #7
    lalu is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Gui text problem

    ok the great moderator can u pls tell me how to add radiobutton in combobox

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Gui text problem

    Quote Originally Posted by lalu View Post
    ok the great moderator can u pls tell me how to add radiobutton in combobox
    If you have a question, get your own thread. Don't hijack another poster's thread.

    Your post above and this response will be removed form the thread later.

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

  9. #9
    Arr
    Arr is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: Gui text problem

    Thanks. I resolve that problem with JTextArea. Its working great.¨

    But there are plenty more problems.

    Ofc I got Jlabel here same as in the previous one. I need one more (for text) under the first. Its just one line so I dont want to use JtextArea or something like that. Anyone knows how to do this? Or is JLabel bad for that? Thanks again.
    label1 = new JLabel("You Lose!",JLabel.CENTER);
    label1.setVerticalTextPosition(JLabel.BOTTOM);
    label1.setHorizontalTextPosition(JLabel.CENTER);
    add(label1);
    Last edited by Arr; 04-27-2012 at 05:37 PM.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Gui text problem

    Have you used JOptionPane? The message parameter, classed as Object in the API, can be a String[] array, in which case the elements of the array are stacked vertically; it can be an array of Swing components, which will also be stacked vertically.

    Put your code aside and write a short class with just a main(...) method that calls the static methods of JOptionPane (show...Dialog) with different Objects as the message parameter. You might be surprised how well JOptionPane handles the display of the message.

    I'll get you started:
    Java Code:
    public class TestOptionPane {
    
        public static void main(String[] args) {
            String[] message = {"One", "Two", "Three"};
            JOptiionPane.showMessageDialog(null, message);
        }
    }
    Some of the other methods can allow you to set the text of the buttons before displaying the dialog. Read the API.

    db

    Note: for any real program, make sure to call Swing constructors and methods on the EDT.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #11
    Arr
    Arr is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: Gui text problem

    Quote Originally Posted by DarrylBurke View Post
    Have you used JOptionPane? The message parameter, classed as Object in the API, can be a String[] array, in which case the elements of the array are stacked vertically; it can be an array of Swing components, which will also be stacked vertically.

    Put your code aside and write a short class with just a main(...) method that calls the static methods of JOptionPane (show...Dialog) with different Objects as the message parameter. You might be surprised how well JOptionPane handles the display of the message.

    I'll get you started:
    Java Code:
    public class TestOptionPane {
    
        public static void main(String[] args) {
            String[] message = {"One", "Two", "Three"};
            JOptiionPane.showMessageDialog(null, message);
        }
    }
    Some of the other methods can allow you to set the text of the buttons before displaying the dialog. Read the API.

    db

    Note: for any real program, make sure to call Swing constructors and methods on the EDT.
    Oh i knew JOptiionPanels but, there are two problems with them.

    I need my own buttons because I want add a texture to them + that icon really destroys that.
    Thanks for help.

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Gui text problem

    You haven't studied and played with the JOptionPane long enough. The code I posted was just to get you started.

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

Similar Threads

  1. GUI Button text problem
    By simon.black325 in forum New To Java
    Replies: 4
    Last Post: 09-28-2011, 05:20 AM
  2. problem in spliting a text
    By vipinvijay in forum New To Java
    Replies: 3
    Last Post: 01-10-2011, 11:09 PM
  3. Problem With Text Fields!
    By freshoreo in forum AWT / Swing
    Replies: 3
    Last Post: 08-04-2008, 10:52 PM
  4. Problem in Text Editor
    By mustahsan4u in forum New To Java
    Replies: 2
    Last Post: 03-26-2008, 03:34 PM
  5. Text Area problem
    By mcal in forum New To Java
    Replies: 0
    Last Post: 02-11-2008, 10:42 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
  •