This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
bananaman
Indestructible


Calc Guru


Joined: 12 Sep 2005
Posts: 1124

Posted: 13 Feb 2008 01:01:08 pm    Post subject:

I'm using a JTextField in a Java Application and I am wondering if it is possible to put a picture for the background of the field. I know that with most J... components you can use setIcon method to place a picture for the background of the component. The JTextField component does not have such a method. Is there a way to place a gif image as the background of a JTextField?
Back to top
Zaphod Beeblebrox


Member


Joined: 02 Jul 2007
Posts: 119

Posted: 13 Feb 2008 04:55:41 pm    Post subject:

Their are few things I can think of, none of which I think will work:

[font="Courier"]TextArea.getAccessibleContextContext().setBackground(icon icon)

TextArea.getAccessibleContextContext().setIcon(icon icon)


If you declared this with something like:
[font="Courier"]JPanel panel = new JPanel("_");
JTextArea textArea = new JTextArea(args);
panel.add(textArea);

You could add in a line that says [font="Courier"]panel.setIcon(icon);.

That's all I can think of.
Back to top
elfprince13
Retired


Super Elite (Last Title)


Joined: 11 Apr 2005
Posts: 3500

Posted: 13 Feb 2008 08:40:53 pm    Post subject:

this is disgustingly hackish, but something along the lines of this:


Code:
JTextField jtf = new JTextField(){
paint(Graphics g){
g.setFont(this.getFont());
IconImage ii = new IconImage("lol.png");
ii.paintIcon(jtf, g, 0, 0);
g.drawString(jtf.getText(), jtf.getInsets().left, jtf.getInsets().top);
}
};


oughta do it.
Back to top
bananaman
Indestructible


Calc Guru


Joined: 12 Sep 2005
Posts: 1124

Posted: 13 Feb 2008 09:51:36 pm    Post subject:

That is extremely hackish. For what I am doing I think I will make it so that if you want to edit the field you will have to open up a dialog box and then I will just make the component on the screen be a button so that I can have its background be an image and when you click you get to edit the content.
Back to top
elfprince13
Retired


Super Elite (Last Title)


Joined: 11 Apr 2005
Posts: 3500

Posted: 15 Feb 2008 04:26:26 pm    Post subject:

umm...why not just extend Label or button or something like that with a keylistener + focuslistener?
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement