Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with Joptionpane  RSS feed

 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have got this piece of code:

Which if you run it will make a cool Joptionpane.
I want to go through these one by one, starting with:
1. What is the code to put text in the top left hand corner of the JOptionpane.
And is there a way to do an auto scroll. So as your character goes up it scrolls automagically.

Any help would be appreciated
Bod.
 
Fred Kleinschmidt
Bartender
Posts: 509
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no JOptionPane here. All you have is a GUI program consisting of a JFrame with scrollable (but empty) JPanel as its center child.



 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the code to put text in the top left hand corner of the JOptionpane.


As already mentioned you are using a JFrame, not a JOptionPane.

So start by looking at the JFrame API for the various methods you can use on a frame. Maybe something like setText(...) or setTitle().

You can also start by reading the section from the Swing tutorial on How to Make Frames for a working example.

The tutorial will also show you how to better structure your code so the GUI is created on the Event Dispatch Thread.

So as your character goes up it scrolls automagically.


What character? We are not mind readers.
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Kleinschmidt wrote:There is no JOptionPane here. All you have is a GUI program consisting of a JFrame with scrollable (but empty) JPanel as its center child.




Ahh I see, so to get this to work I need to use a JOptionframe. Thanks!
 
Liutauras Vilda
Marshal
Posts: 3839
206
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bod McLeon wrote:Ahh I see, so to get this to work I need to use a JOptionframe.

There is no such class. There is JOptionPane. Look in Java API for more information. And for its use in Oracle Java tutorials.
 
Piet Souris
Rancher
Posts: 1783
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe it is time to elaborate a little on what it is you are trying to achieve. Did you read the tutorial on JScrollPanes I pointed to in your previous post?
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:What character? We are not mind readers.


This is meant to be Colour Switch, for those who don't know what this is, Google it (use images). It will make your life easier. In Colour Switch you have a dot as your character and every time you click, the character (dot) will jump up. So what I am aiming for is the frame thing to auto scroll upwards as you get near the top.
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what I am aiming for is the frame thing to auto scroll upwards as you get near the top.  


Use proper terminology. A frame doesn't scroll.

You have already been given a link on how to use a scroll pane is a previous question. So read the link and ask proper questions so we don't have to keep asking for clarification.

To auto scroll you can use the scrollRectToVisible(...) method of the component added to the scroll pane.

 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!