Results 1 to 12 of 12
Thread: Gui text problem
- 04-23-2012, 04:48 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
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 05:00 PM.
- 04-23-2012, 07:26 PM #2
Re: Gui text problem
Moved from New to Java.
Choose a suitable layout manager.
Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
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.
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
More custom painting.
But, seriously, learn to walk before you try to run.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-25-2012, 10:15 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
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 10:33 PM.
- 04-26-2012, 12:14 AM #4
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-26-2012, 01:24 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
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.
- 04-26-2012, 02:55 PM #6
Re: Gui text problem
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-26-2012, 05:52 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
Re: Gui text problem
ok the great moderator can u pls tell me how to add radiobutton in combobox
- 04-26-2012, 06:48 PM #8
- 04-27-2012, 04:30 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
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 04:37 PM.
- 04-27-2012, 05:15 PM #10
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:Some of the other methods can allow you to set the text of the buttons before displaying the dialog. Read the API.Java Code:public class TestOptionPane { public static void main(String[] args) { String[] message = {"One", "Two", "Three"}; JOptiionPane.showMessageDialog(null, message); } }
db
Note: for any real program, make sure to call Swing constructors and methods on the EDT.Why do they call it rush hour when nothing moves? - Robin Williams
- 04-27-2012, 06:38 PM #11
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
- 04-27-2012, 06:56 PM #12
Similar Threads
-
GUI Button text problem
By simon.black325 in forum New To JavaReplies: 4Last Post: 09-28-2011, 04:20 AM -
problem in spliting a text
By vipinvijay in forum New To JavaReplies: 3Last Post: 01-10-2011, 10:09 PM -
Problem With Text Fields!
By freshoreo in forum AWT / SwingReplies: 3Last Post: 08-04-2008, 09:52 PM -
Problem in Text Editor
By mustahsan4u in forum New To JavaReplies: 2Last Post: 03-26-2008, 02:34 PM -
Text Area problem
By mcal in forum New To JavaReplies: 0Last Post: 02-11-2008, 09:42 PM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks