Java question

Status
Not open for further replies.
I had asked down below about implementing scrolling text, like a stock ticker, in an applet. It was suggested that I could create a JPanel, get the graphics, use graphics.drawString in a loop to print the text. Then I could override the paint/paint component to print the background color over the previous text.

While implementing this, I ran into a problem. I'm pretty new to java so forgive me if this is a very basic question. When I used a regular JPanel, it would at least appear at the top of my window(with buttons under it, like it is supposed to. However, when I make the custom JPanel class, to override, it starts placing my JLabel on top of the buttons, as though it disregards the flow layout manager. Can anyone tell me what I'm doing wrong? Thanks.
 

gumbo

Ars Tribunus Angusticlavius
6,107
What about a different layout manager? You said the JPanel was over the buttons, which with a FlowLayout would only happen if the JFrame parent was confining, forcing the row down.

If you used a BorderLayout, added the ticker to the CENTER, another JPanel to the SOUTH, and your buttons and labels in that JPanel, nothing would be covered. It sounds like you are grabbing the graphics to the parent JPanel also, instead of a new JPanel on that one, correct? If that is the case, try creating a new instance of the panel, and replace the current panel with a standard one.

Code:
-----------------------------------
|   --------------------------    | -----Parent JPanel
|   |       Ticker JPanel    |    |
|   --------------------------    |
|---------------------------------|
|   JLabels and JButtons          |
-----------------------------------

gubmo
 
I am still really having trouble with this one. You had said that I could implement it with either a jlabel or jpanel. Could you briefly explain how you would do this with a JLabel? It seems that if this was possible it would not cause as many problems, as it does not create a new "panel" that is causing so many problems with panels overlapping. I would greatly appreciate it.
 
Status
Not open for further replies.