LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2007, 12:09 PM   #1
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Rep: Reputation: 30
Adding a JList to a Graphics2D


I want to add a JList object from javax.swing.* to a Graphics2D interface, and I don't know how to do that.

Sorry if I formulated my question a little childish but I have no idea of java. If you have any advice....

Thank you!
 
Old 10-28-2007, 06:50 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Could you explain what you're trying to do (in normal English, rather than Java-speak) please? Why do you want to add a JList to a Graphics2D? I'm not even sure what you mean by that.
 
Old 10-28-2007, 07:19 AM   #3
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
well I want to make am applet. Here is what I have done so far http://spank.as.ro/

I want to insert in the bottom left square a JList to enter the events that I have done in the big window. Something like a history.

The window is created with
Code:
		image=(BufferedImage)createImage(this.getSize().width,this.getSize().height);
		graphics=(Graphics2D)image.getGraphics();
in the init() function of the aplet
 
Old 10-28-2007, 07:37 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You need to add your JList to some kind of container (like a (J)Panel, for example).
 
Old 10-28-2007, 07:43 AM   #5
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
and can I add a JPanel to my interface ?
 
Old 10-28-2007, 07:52 AM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Yes, you can.
 
Old 10-28-2007, 07:55 AM   #7
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
any hints on how to do that? just to save some time.... because I still have to work allot on it
 
Old 10-28-2007, 08:14 AM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
I haven't done any applet programming myself, but here's a simple example (that I've pretty much taken from the Java tutorial and changed a bit. It creates an applet with a button on a panel.

Code:
import javax.swing.*; // For JPanel

public class Test extends JApplet {

    JPanel panel;

    public void init() {
        //Execute a job on the event-dispatching thread:
        //creating this applet's GUI.
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    createGUI();
                }
            });
        } catch (Exception e) {
            System.err.println("createGUI didn't successfully complete");
        }

        //addItem(false, "initializing... ");
    }

    private void createGUI() {        
        //Create the text field and make it uneditable.
        panel = new JPanel();
        JButton b = new JButton("Stuff");
	panel.add(b);

        //Set the layout manager so that the text field will be
        //as wide as possible.
        setLayout(new java.awt.GridLayout(1,0));

        //Add the text field to the applet.
        add(panel);
    }

    // Other methods like start() and stop() need to go here
}
 
Old 10-28-2007, 08:25 AM   #9
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You may want to add your JList to a JScrollPane and then add that JScrollPane to the panel, but obviously that's if you think you'll need scrollbars!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing Lines from a JList by using JasperReports MRMadhav Programming 0 08-19-2006 01:07 AM
Adding more SWAP after adding memory marc1978 Linux - General 6 03-19-2006 07:13 PM
Adding a new HD hywaydave Linux - Newbie 4 05-02-2005 03:22 PM
ip adding help ranger12002 Linux - General 3 07-01-2003 10:37 AM
adding a HD vicente Linux - General 2 09-12-2001 09:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration