Jump to content
  • Advertisement
Sign in to follow this  

[java] Painting Semi-transparent versions of Components

This topic is 2885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am building a console for development purposes. I already have the capability to stream text from System.out/err to a JTextPane as well as send input using system.in into it. I am wanting to know if it is possible to get the graphic outline of the JScrollPane with the JTextPane and draw a semi-transparent version of the components over-top of everything when my console activation key is pressed. I am more of a console programmer then GUI.

The developers of Runescape have something similar to what I want:


How would I go about doing something like the picture above? I don't need code, I just need links to resources. I have searched for: getting component graphics, painting semi transparent components, and similar things.

Any help would be greatly appreciated.

One idea I had was to paint a set amount of lines from the text-area at a time (3-5) and as you type commands, it removes the first item.

Share this post

Link to post
Share on other sites
This type of blending is translucency.

The only way I can think todo that with Swing is to extend those classes and override "paintComponent(...)".

Check out this article, it's got some useful information.

Also depending on the complexity of what you're rendering, you may find it easier to use AlphaComposite, rather than setting alpha individually through "Graphics2D.setColor(...)".

Share this post

Link to post
Share on other sites
I have managed to rig up a working console over night.

Here is a preview:


I can only output text from my console.println method and data from system.out/err into the console.

I store all of my lines of text into a linkedlist. If the amount of lines exceed a specified amount, it will automatically delete the top item.

This is my render method in my console which is called in the render method of my game canvas.
public void Render(Graphics g) {
g.setColor(new Color(0, 0, 150, 100));
g.fillRect(0, 0, width, height);
FontMetrics fm;
fm = g.getFontMetrics();
String greeting = "Game Console Version 1.0";
Font oldFont = g.getFont();
Font tempFont = new Font(oldFont.getFontName(),Font.BOLD,12);
g.drawString(greeting, (width - fm.stringWidth(greeting)) / 2,15);
g.drawLine(0, 25, width, 25);
int y = 45;

for (int i = 0; i < Lines.size(); i++) {
if (Lines.get(i) != null) {
g.drawString(Lines.get(i), 5, y);

y += fm.getFont().getSize() + 3;

I have to call the update method of the console in the update method of the game canvas.

There is probably a better way of doing my console, but I just need something within the game to debug things.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!