473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

About AWT List

Hello

I am trying to attach a pop up menu in List
That is going fine
But I donno why for some area it is showing and for another it is not
Please help me.
Jul 23 '07 #1
5 1276
JosAH
11,448 Expert 8TB
Hello

I am trying to attach a pop up menu in List
That is going fine
But I donno why for some area it is showing and for another it is not
Please help me.
Can you show us some snippets of (relevant) code please?

kind regards,

Jos
Jul 23 '07 #2
Can you show us some snippets of (relevant) code please?

kind regards,

Jos

// Copyright (c) 2007 Ericsson AB. All rights reserved.

package testpackage;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTextArea;

public class CTestClass implements ActionListener
{
private JFrame frame;
private JTextArea area;
private JLabel label;
private List wordList;
public static JPopupMenu popup;

public CTestClass()
{
frame = new JFrame("popup menu");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.getContentPane().setLayout(new GridLayout(3, 1));

area = new JTextArea();
label = new JLabel("Sample");
wordList = new List();

popup = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("A popup menu item");
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Another popup menu item");
menuItem.addActionListener(this);
popup.add(menuItem);

// Add listener to components that can bring up popup menus.
MouseListener popupListener = new PopupListener();
area.addMouseListener(popupListener);
wordList.addMouseListener(popupListener);
frame.getContentPane().add(area);
frame.getContentPane().add(label);
System.out.print(popup.getForeground());

frame.getContentPane().add(wordList);
frame.setSize(400, 300);
frame.setVisible(true);

}

public void actionPerformed(ActionEvent e)
{

}

public static void main(String[] args)
{
new CTestClass();
}
}

class PopupListener extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
maybeShowPopup(e);
}

public void mouseReleased(MouseEvent e)
{
maybeShowPopup(e);
}

private void maybeShowPopup(MouseEvent e)
{
if (e.isPopupTrigger())
{
CTestClass.popup.show(e.getComponent(), e.getX(), e.getY());
}
}
}

If you run this program in any editor like eclipse
It will create frame in which there are 3 rows and 1 column
0,0 -> TEXTAREA
1,0 -> LABEL
2,0 -> List

I have attached popuplistener to TEXTAREA and LIST
Now when you right click at any plcae within TEXTAREA it is working fine
but try the same in LIST you will know the problem

Thanks
Jul 23 '07 #3
JosAH
11,448 Expert 8TB
You're mixing AWT objects with Swing objects; the two don't go well together,
i.e. the AWT objects are 'heavyweight', they use the system's windowing objects.
Swing doesn't so AWT doesn't know about the Swing objects and vice versa.

I suggest you'd use a JList instead (and none of the other AWT components).

kind regards,

Jos
Jul 23 '07 #4
You're mixing AWT objects with Swing objects; the two don't go well together,
i.e. the AWT objects are 'heavyweight', they use the system's windowing objects.
Swing doesn't so AWT doesn't know about the Swing objects and vice versa.

I suggest you'd use a JList instead (and none of the other AWT components).

kind regards,

Jos

Thanks Jos
You got the problem
Now I used JList and the problem is Solved
Jul 24 '07 #5
JosAH
11,448 Expert 8TB
Thanks Jos
You got the problem
Now I used JList and the problem is Solved
You're welcome of course; mixing AWT and Swing components is a frequent
mistake; it can be a bit confusing when you just read the class documentation.

kind regards,

Jos
Jul 24 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

39
by: Marco Aschwanden | last post by:
Hi I don't have to talk about the beauty of Python and its clear and readable syntax... but there are a few things that striked me while learning Python. I have collected those thoughts. I am...
3
by: fdsl ysnh | last post by:
--- python-list-request@python.orgдµÀ: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, > visit >...
17
by: kj | last post by:
How can one test if a pointer has been "freed" (i.e. with free())? My naive assumption was that such a pointer would equal NULL, but not so. Thanks, kj -- NOTE: In my address everything...
105
by: Christoph Zwerschke | last post by:
Sometimes I find myself stumbling over Python issues which have to do with what I perceive as a lack of orthogonality. For instance, I just wanted to use the index() method on a tuple which does...
2
by: pinkfog | last post by:
Hello,all I m just a newbie to c,and now i m learning quick sorting,i dont very undertand this algorrithm,can someone kind to explain it to me? the code: <quote> void quick_sort(int a ,int low...
3
by: neilcancer | last post by:
My English is poor... There are some sort algorithms which sort a sequencial list. The sequencial list was defined in "list-seq.h". sort_and_time() accepts one of these sort functions. It uses...
10
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
75
by: Steven T. Hatton | last post by:
No, this is not a troll, and I am not promoting Java, C-flat, D, APL, Bash, Mathematica, SML, or LISP. A college teacher recently posted to this newsgroup regarding her observation that there has...
10
by: Ruan | last post by:
My confusion comes from the following piece of code: memo = {1:1, 2:1} def fib_memo(n): global memo if not n in memo: memo = fib_memo(n-1) + fib_memo(n-2) return memo I used to think that...
1
by: BillG | last post by:
I am developing a business app using asp.net that will have 2 different types of forms, a list view of data and then a detail view. The list views are placed on a content panel in a master page. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.