Scrollable BackGround Image with text input fields using Java - java

I'm pretty new to Java and have been stuck for hours trying to figure out how to do the following...
I would like to create a Java program that shows a panel (has a background image that is scrollable) that contains input boxes. Think of a panel that shows at 800by800, but the image is more like 2000x2000, with input boxes all over. As you scroll, nothing should move.
I'd be very greatful if anyone can point me the right direction or has a sample piece of code that they would share.
Thank You!

You could try a JScrollPane: JScrollPane

Related

Java: Clickable grid project - what to use? (JFrames & JPanels)?

I'm currently getting started on a project where I use a grid for a game (Dot game, but that's not very important). Basically, it will be a grid of dots, where a player can click on the lines between the dots (like this).
I currently am using a JFrame, and was thinking about ways I could populate it with JPanel components to create clickable regions. Currently, I was thinking about trying to create for loops to correctly populate it, but I don't know how I could efficiently do this.
Any recommendations for how to do this? I'm not asking people to write code for me, just point me in the right direction. Is there any layout (GridLayout?) that would work well for this?
Welp, I ended up figuring it out on my own, but using a soulution not quite ideal. I have a for loop making every odd line have a black panel, then clickable jbutton, then a black panel, etc. Every even line has a clickable j button, then a white middle pannel, then a clickable jbutton, etc.
Looks like this:
https://gyazo.com/79b80dfe13b017a234e6fad2aa224d58

JFrame 'Console' style text

I have probably a quick question but here it goes. I am making a game (new to programming) and I want a text field in the middle of my game that I can easily add to kind of like a console. You will be able to view the beginning from late into the game.
Example:
Welcome to the game.
Added when you click a button
More text is added.
You click a different button
More text is added.
I am currently using a JLabel for this but it's a .setText which is inconvenient when I want to have tons of text throughout my game. As well, how could I add a scrollbar to this?
I'd guess you are looking for JTextArea .

BufferedImage Compatible with JTextArea and JTextField

I have been researching this topic a lot and haven't found anything that tells me I can add a BufferedImagento a JTextArea or JTextField. I am making a chat application and trying to add smiley faces for the chat. What I am trying to do is put the image right next to the string like it is text. I was thinking if you could put the Buffered image in the format of a char that would help. Please help me! Thank you!
I'd also give a try to JEditorPane.
For motivation see: http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html.
I've noticed that most of the chat applications, show you what you and others wrote in one window (could be JEditorPane with all the smilies displayed as pics) and bellow you can have editable JTextArea showing just text.
The problem is that JTextArea and JTextField, are really only meant to show text, in order to implement something that mixes thetext with images, you would need to extend JTextArea and modify the paintComponentMethod to do custom rendering.

JEditorPane, or any java text area fill the JFrame?

I'm writing a simple text editor in java, I have done it before now I have some new ideas, normally when I put in a JTextArea when I have a FlowLayout on my JFrame it will fill what is left of the JFrame. However this time it's not. Could someone help me out trying to get it to fill the rest of my JFrame? Thanks!
http://docs.oracle.com/javase/tutorial/uiswing/layout/layoutlist.html
Java does have various layouts. For making dynamic body changes you have to learn more flexible layouts like grid or grid bag layout. Hope this help.

GUI components of a memory game

I am working on a homework so i am not asking for code, i am trying to make this by myself. by the way, i am stuck again with the GUI part and have little problems with code part. first things is about button size and image size. i didnt use methods for size of buttons just set the image as an icon for the button. but as you see below, buttons dont fit the image.
second thing is how can i first disable the icon and when user presses to button it will reveal the icon ?. and how can i embed 8 pictures in a loop? can i create an array for images... i appreciate if you can help me. and thanks anyway : )
I'd start with How to Use Buttons. JToggleButton works well for this, as you can change the Icon in an ItemListener based on the button's selected state. Examples may be found here and here.

Categories