Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButton and opening new window

 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I am having trouble, when I click on mu button i get a window up with a grey background.
I want to get a window up with a white background and the text "HOW CAN I DO THIS" showing, the text should not be editable and a scroll pane so that if I want to put more text in the textArea I can.
so if any of you lovely people want to help me I would be most Grateful
Thanks
Ben
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You never added the JPanel to the JFrame.

You don't need to setVisible() on the JPanel. That is the default behavior. Another thing I am wondering that doesn't have anything to do with your question is why you are processing a Button click with a MouseEvent?
 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Gregg,
Thanks for yoy help it has done wonders.

You don't need to setVisible() on the JPanel. That is the default behavior. Another thing I am wondering that doesn't have anything to do with your question is why you are processing a Button click with a MouseEvent?

The reason I have the MouseEvent is that I am developing the code using Visual Age for Java, and it automatically gives you a MouseEvent.
Thanks Again
Ben
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ben riches:
The reason I have the MouseEvent is that I am developing the code using Visual Age for Java, and it automatically gives you a MouseEvent.
Thanks Again
Ben

Weird. It is still a JButton though, right? It should be using an ActionEvent. But whatever is working...
 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Again Gregg,
I have another question, How can I add an Image to my text area (if possible). if not possible what is the best solution to adding images and text to and area like I have already?
Thanks
Ben
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't add an image to a Text Area. You can add an image to a JTextPane and/or a JEditorPane. You can find tutorials on this here and/or you can use the Search feature on this forum because this has been asked many times in the past.
Another approach you could do is you could add an image to a JLabel and place it above or below the TextArea. Not sure if that is the look you are going for. My first suggestion is your best bet if you need anything between words/sentences in your TextArea.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic