473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

explain a code for swing

82
I want to draw a text on a JPanel.I know about method drawString but i can't make it work. Then i found a code in the Internet :

learning java

but i can't understand how works? If i put in str_x and str_y , 0 and 0 it doesn't prints me anything. If i leave them as it is it prints me the string but only in the center of x-axis, look


if i put something else as example drawString("hi", 20,20) still doesn't print anything
thanks in advance!
Apr 5 '08 #1
4 1329
kalar
82
because i can't edit my post:
i have these problmes and with other draw... methods. So i guess my mistake is in the way that i get the dimensions? What should i do in order to work?
Apr 5 '08 #2
JosAH
11,448 Expert 8TB
because i can't edit my post:
i have these problmes and with other draw... methods. So i guess my mistake is in the way that i get the dimensions? What should i do in order to work?
For starters: if you want to print a String starting at position x, y, the left most
position will be x and the *baseline* of the String will be at position y, i.e. only
the descenders of the characters will be below (i.e. a larger y coordinate) that
baseline. If you want to print a String at position 0,0 most if not all of the String
won't be visible (above the visible area).

Another remark: if you print characters (a String) in red on a red background
you won't see them of course; are you sure you have set the foreground color
to something else before you draw the String?

kind regards,

Jos
Apr 6 '08 #3
kalar
82
Thank you Jos i understand how works,(i put something like 0,10 and i saw the letters on the screen)
Apr 6 '08 #4
JosAH
11,448 Expert 8TB
Thank you Jos i understand how works,(i put something like 0,10 and i saw the letters on the screen)
Good; moral of the story: always read the darn^H^H^H^H fine API documentation
before you even *think* of typing something in front of your computer. It can only
lead to misery; proof: see the current state of ICT in the world ;-)

kind regards,

Jos
Apr 6 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Scott Khan | last post by:
We have a Java Swing position. Need consultants ASAP. Position : Java Swing XML / SOAP - FX / Brokerage Requirements : Swing - JTrees / Jtables. other swing classes. etc. Java/ J2EE. JDK...
6
by: Joseph | last post by:
hi 1) i plan on having an awt canvas component (to draw graphs) on a JFrame with other swing components..will this be okay? i've read that swing and awt aren't compatible.. 2)Also, if i...
3
by: bergel | last post by:
Hello, Does anyone already have some experience in mixing AWT and Swing? Is it conceptually doable? Does the design of Swing prevent interaction between an AWT and a Swing widget? Regards,...
3
by: Sherrod Faulks | last post by:
I'm using Jython and in the python script I do: from javax import swing result = javax.swing.JOptionPane.showInputDialog(wC, cmd,"Prompt from " + client.serverName, JOptionPane.PLAIN_MESSAGE) ...
9
by: F. GEIGER | last post by:
I've dev'ed a Python prototype of an app, that besides the internals making it up has a gui. While test-driven dev'ing the app's internals in Python is fun as usual, dev'ing the GUI is not so...
1
by: Nandan | last post by:
hello, can I ask a jython question here? when I use the jython interpreter I have no problem with the statement: from java import lang from javax import swing but when I put this in a...
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
13
by: carlos123 | last post by:
ok the following code , is the code for my program, basicly, i use bluej, so i can just copy and paste some code into the forums and someone else can copy it in to their editor, so basicly i want...
6
crystal2005
by: crystal2005 | last post by:
Hi there, I need some help to correct my code. I would like to create a menu bar with the implementation of OO. So, i think i can edit and change it easyly if i use some classes. package...
6
by: Kid Programmer | last post by:
This is pretty stupid. You can create the same program one using this much code:/* * blah.java * * Created on May 26, 2008, 9:35 AM */ package blah; /** *
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.