Swing/AWT/SWT :: Create A Sub Menu For Every List Item In A Jlist

Oct 8, 2014

I would like to create a sub menu for every list item in a Jlist. I need the UI like avast interface. If we hover over an list item, its sub menu should be shown. I attempted to put an sub menu but didn't work. Is this possible in Swing?

View Replies


ADVERTISEMENT

Create Instance Of Class Used To Populate DefaultListModel When JList Item Selected

Jan 28, 2015

New to Java Swing. What I am trying to achieve here is to create an instance of the class used to populate the DefaultListModel when a JList item is selected. All examples I have seen show how to return the text displayed in the JList which really is of no practical use.

I have achieved what I want to achieve in that I am successfuly creating the selected object within my ListCellRenderer class.

For the purpose of testing I am using a call to the JOptionPane.showMessageDialog method to display the id of the selected object.

So, I launch the JFrame, the JList is populated, I select an item from the JList and the id value is displayed in the prompt. All this works fine except for one thing.

When I click OK on the JOptionPane.showMessageDialog prompt, the prompt disappears and reappears. The system seems to be in a loop. It is behaving as if the change or click event handler on the JList keeps firing.

This happens even without the creation of the object:

BookEntry be = (BookEntry)list.getModel().getElementAt(list.getSelectedIndex());

I have scoured the code and object properties to see if I can figure out where this behaviour is coming from without success.

All there is in the JFrame design view is a single JList with a variable name of "list". Everything else is in code as below:

Here is the .java code. Its not that complex

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListCellRenderer;
import javax.swing.DefaultListModel;
 public class NewJFrame3 extends javax.swing.JFrame {
 
[Code] .....

View Replies View Related

Swing/AWT/SWT :: Changing Color Of JList Item

Oct 23, 2014

is there a good way to change the color of a JList item that isn't selected? I'm throwing my hand at building a client/server chat app and on the client side, I need to highlight the name of the person (which is in a JList) who has sent a message to the client GUI.

View Replies View Related

Swing/AWT/SWT :: Popup Menu Will Become Invisible Does Not Capture Selected Value / Item

Nov 1, 2014

I have a combobox with this PopupMenuListener. All works fine, except that the popupMenuWillBecomeInvisible method does not capture the selection made and neither does it show the selection.

PopupMenuListener pmlMqMessagePurged = new PopupMenuListener() {
@SuppressWarnings("unchecked")
public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
try {
JdbcSqlServerDataSource ds = new JdbcSqlServerDataSource(
DbConnectionURL.UToolDbHostName, 0,

[Code] .....

The popupMenuWillBecomeInvisible does fire but the System.out.println() returns 'nul'l as answer to the value i have selected from the combobox.

View Replies View Related

Swing/AWT/SWT :: Java GUI With Separate Class For JList - Adding Items To The List?

Sep 19, 2014

I am trying to create a GUI interface in swing which consists of four classes: a GUI class, which creates a main JPanel, a label, and a JList, which it takes from the second class, a MovesList class that contains a JList and the stuff needed to interface with it. It also has a main class, which basically just creates an object of the GUI class for the main window, and an Other class from which I would like to be able to add an item to the JList. I created methods in the MovesList class to get each component (like getMoveslist, or getMovesListScrollPane), which I then used to create the JList in the GUI class. I also created an addMove method so that I can add an item to the JList from any class through a MovesList object. However, this addMove method only works when called from the GUI or MovesList classes -- it does nothing when I collect from the Other class.

Here is my code:

//Main class
public class TestProject {
public static void main(String[] args) {
GUI mainWindow = new GUI();
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

[Code] ....

When I run this code, I get a window with a JLabel that says "Moves," and a JList that contains five elements -- test 1-test 5, but not a sixth "test from other class." ( using the add move method ) However, when I click on the window, the addMove method is also called, and successfully adds "test 6" to the list.

View Replies View Related

How To Add Menu Item That Can Be Clicked To Open Up About Dialog Box

Dec 28, 2014

I have a question and wasn't able to find what I needed through the search. I am currently using Netbeans 8.0 and working on a desktop app. I have a main GUI file where I am going to add a menu item that can be clicked to open up an "About" Dialog box. The problem is, I don't know how to do this

The file are...

MainGui.java
About.java

How would I go about opening the About.java when clicking on a menu item? I tried using...

new About();
About.setVisible(true);

But this just gave a compilation error.

View Replies View Related

Writing A Program Using Switch Statement - Allow Users To Choose Item Of A Menu

Oct 5, 2014

Write a program using switch statement to allow users to choose an item of a menu. For example, the menu looks like the following.

File menu
1. Open
2. Close
3. Save
4. Exit
Enter your choice:

If you type 1, then your program should print out "Open is selected" (double quotes not included).

Notice:
(1) Using Scanner to get user choice;
(2) If the number user input is not in {1,2,3,4}, your program should let user know that.

Here's what I have:

public static void main (String[] args) {
int user = 1
switch (1) {
case value: 1
System.out.println ("Open is selected");

[Code] .....

View Replies View Related

Create A Menu Where The User Can Create A New Account?

Oct 5, 2014

I'm having some difficulty with my bank account project. I'm supposed to create a menu where the user can create a new account, withdraw, deposit, view their balance, and exit. There's issues with the account creation.

Here's my necessitated class below: BankAccount, TestBankAccount, SavingsAccount, CurrentAccount, and Bank

/*---------------------------------------------------
Plagiarism Statement
 
I certify that this assignment is my own work and that I have not copied in part or whole or otherwise plagiarized the work of other students and/or persons.
 
----------------------------------------------------------*/ 

package BankAccount;
 import java.util.Date;
import java.util.Random;
 //Project 3
public class BankAccount {
protected static int accountID;

[code]....

View Replies View Related

How To Create A Menu

May 12, 2014

I'm trying to create a GUI java application.

I want a menu with buttons that looks like this:

Button 1: Start
Button 2: Help
Button 3: About Me

If you press one of the buttons you will get to another frame with new buttons, new labels and so on.

Next step for instance if you press button 1, I'd like my program to get this frame:

Different alternatives, and a text field with a button. One commando leads to one new JFrame with new buttons, text fields and so on.

View Replies View Related

JSP :: Choose A Value From List Item?

Feb 11, 2015

I need to choose the value of a list item in jsp. There are many employees in various departments and i need to choose that employees in department wise.

Example. I have two list items in jsp

1. Select dept_no,dept_name from departments
2. SElect emp_name from employees, departments where emp_dept_no=curr_dept_no and curr_dept_no = dept_no

These two are the list items. When i choose the department from the first list item i need to display the employees in that particular department in the second list.

View Replies View Related

List Only Appends One Item

Feb 23, 2014

Node inside a linkedlist

SomeInterface has an

Java Code: addLast() mh_sh_highlight_all('java');

Method that should add a node at the end of the list

Java Code:

public sizeCount=0;
public LinkedList<T> implements SomeInterface<T>{protected class Node<T>{
privateT data;
private Node<T> head,tail;
protected Node(T data,Node<T>tail){
this.data=data;head=null;this.tail=tail;}

[Code] ....

View Replies View Related

Create JTable When Click On New On Menu Bar

Dec 5, 2014

I want to create a Jtable when i click on "new" on the menu bar,but if i click on it, i still not see the table.Here is the code:

package mestint
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.*;

[code].....

View Replies View Related

Swing/AWT/SWT :: Using JList Instead Of JTable?

Apr 18, 2014

Can I use Jlist instead of Jtable for showing database table data (select * from employee) in my code?

View Replies View Related

How To Insert New Item In Doubly Linked List

Oct 26, 2014

How can I insert a new item at the middle of a BookList . I have also got a Book class represting Book objects and a inner class BookNode referencing them.

public void add(Book newBook)
{ BookNode newNode = new BookNode(newBook);
if (firstNode == null){
// no nodes in the list so add newNode at start
firstNode = newNode;
tempNode = newNode ; }

[Code] ....

View Replies View Related

How To Select Item From A List And Add It To Display Java GUI

Apr 28, 2014

I'm making an application that will allow users to view several displays simultaneously. I'm trying to make it so that the user should be able to select one of the items from a list then hit a radio button add them to the display. And there will be a second button to remove them from the display. Oh and there will always be alteast one display.

View Replies View Related

Swing/AWT/SWT :: Adding Images To JLIST

Apr 14, 2015

I am currently creating a Twitter Application within Java Swing using JSON. I have the JList populating with Home feeds but i also want to get Images displaying next to the Text ...

currently all i am getting is [URL] ....

So a am able to get the URL Link but getting that to a Image seems to be the problem

/ArrayLists
final ArrayList<String> TweetArray = new ArrayList<String>(); //Array List for Users Tweets..
final static ArrayList<String> incomingTweets = new ArrayList<String>(); //ArrayList for Incoming Tweets.
ArrayList<String> arrayImages = new ArrayList<String>();//ArrayList for incoming Tweet Profile Images
private Map<String, ImageIcon> imageMap;

[Code] ....

View Replies View Related

Linked List - How To Insert Removed Item Into Buckets

Jan 8, 2014

//Add three red items to the list
LinkedList red= new LinkedList();
red.add(0,"1");
red.add(1,"2");
red.add(2,"3");

//create abc bucket to red items.
LinkedList abcred= new LinkedList();
red.remove(0);

//So how to insert removed item into abc buckets (similar to stack data structure)

I want to remove all red items and after that add to "abcred" using one by one. So, how to do that?

View Replies View Related

Adding Stars After Each Item In The List - For Loop Isn't Working?

Feb 26, 2014

This is supposed to be a method that adds stars after each item in the list.

Java Code:

import java.util.ArrayList;
public class ClientProgram {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("the");

[Code] ...

I'm guessing it's because list.size() changes, though but it should only find that value in the beginning, so it shouldn't be a problem?

View Replies View Related

User To Select Item From Printed Out Array List

Jun 24, 2014

I am trying to have a user select from a printed out array list, instead of having the user type in the "bill type" each time there is a bill to avoid user error as much as possible. For example I would like to have it print out like this:

"Select bill type from list:

1. Rent
2. Car
3. etc..."

and I would like the user to choose a number and not type in the "bill type". I don't want to use "Switch case" because it would need to be an expanding and I don't think "switch case" can do that.

Here is the code:

package homebudget;
class Spending
{
//Do i need a totalAmount variable?
String type;
double amount;
int year, month, day;
public Spending()

[Code] ....

case 2:
//Give option to enter a new expense or pick from list.
//How to do this? If Statement that doesn't list duplicates, or a while search?

resp = JOptionPane.showInputDialog("Enter the type of expense:");
type = resp;
resp = JOptionPane.showInputDialog("Enter the amount of the expense:");
amount = Double.parseDouble(resp);

[Code] .....

View Replies View Related

Create Address Book Complete With Menu System

Oct 19, 2014

So for the last few weeks I have been working on a Java project for school. I see the light at the end of the tunnel, but I have run into some speed bumps with my main class. It was working fine, but I was pulling an all night and I deleted some of my code by mistake.Now I am not seeing what is exactly wrong. Anyways, the project was to create an address book complete with a menu system.

Here are all of my classes:

import java.util.ArrayList;
/**
* A model of an address book which keeps track of contacts.
* An address book object should keep track of the concept of a current contact (think index).
* You must use an ArrayList for your implementation.
*/
public class AddressBook {
Contact contact = new Contact();

[code]....

View Replies View Related

Swing/AWT/SWT :: Alternative To Making Static JList?

Sep 16, 2014

I am currently writing a chess application in Java swing. For the GUI part, I have one MainWindow class, and one ChessBoard class. The MainWindow has a main panel, in which is contained 1) a panel containing the chessboard from the chessboard class (a grid layout array of 64 JLabels), 2) a JLabel status bar, and 3) a JList to hold the moves of the game. I have a movePiece method in the chessboard class, which I would like to add the move and question to the moves list, which is contained in the main window class.

However, since JList is some special type, I can't make it static ( that gives me an error ). I also tried creating a method in the main window class to add a move to the list, which I would then access via the chessboard class. However, I can't make the method static, because it is referencing a non-static variable ( the JList ), and since the Main window class already has an object of the chessboard class, trying to create a main window object in the chessboard class creates a stack overflow error.

View Replies View Related

JSF :: 2.2 And Netbeans 8.0 - Create A Website That Has Common Header / Footer And Menu

Aug 26, 2014

I am working with Netbeans 8.0 and JSF2.2. I am trying to create a web site that has a common header, footer, and menu. The only part that would be dynamic is the content. So here goes...

1) I need a common template that has 4 parts, Header, Footer, Menu, Content
2) The header, footer and menu are to be in a separate files of which are called from the main template
3) The content will change based on the menu item changed
4) The menu has to change the content section only

I know how to do this in HTML but I am trying to set up some thing in JSF to learn more on JSF pages. All I am looking for is an example that I can follow along with having the multiple pages as well having the menu change the content (I have done a ton of internet searching but nothing really fits the bill).

This is the code I have currently.

Index (Main Template)
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Fill Text Fields With Selection From JList

May 2, 2015

I have an addressBook GUI where I have a JList that populates with the contacts names, and once I double click a contacts name I'm wanting to fill the textfields with the contacts corresponding data.

ex) ContactType: Family (enum), Name: Zoidberg, Address: 111 Space Drive, City: New York City, etc...

I've got it to where I select open from the JMenu, it populates the JList, but once I select a contacts name, all the textfields are populated, but only with the contacts name

ex) Name: Zoidberg, Address: Zoidberg, City: Zoidberg, etc....

What am i doing wrong here, and how can i fix it to where it fills out the correct data?

Here's my code so far:

public class AddressBookGUI extends JFrame {
private final int WIDTH = 450;
private final int HEIGHT = 300;
private JLabel currentlySelected;
private JTextField contactTypeTextField;

[code]...

I'm certain the logic is messed up near the end where i set all text fields to the index, because no matter what field i want to fill it's at it's going to set it to whatever index I select, but I don't know how to fix it.

View Replies View Related

JavaFX 2.0 :: Modifying Item In Observable List Doesn't Update ListView

Oct 3, 2014

I am using:

Java:..... 1.8.0_20JavaFX:... 8.0.20-b26 

I have this class:
 
public class Person {
    private SimpleStringProperty name;
    public SimpleStringProperty nameProperty(){
        if(this.name==null){
            this.name=new SimpleStringProperty();

[Code] .....

I have this:

lista = FXCollections.<Person>observableArrayList();
lista.addAll(new Person("uno"),new Person("due"),new Person("tre"));
myListView.setItems(lista);

The problem is if I add /remove an item all is fine, the listView refreshes correctly:

Person p = new Person(tfld_textAdd.getText());
lista.add(0, p);
 
But if I change a value on an item into the observable list it doesn't:

lista.get(0).setName("new value");
 
I also have a table linked in the same way and the table workd correctly after I updated my Java version...

View Replies View Related

Swing/AWT/SWT :: MouseListener Doesn't Work If JList Has Custom CellRenderer

Nov 9, 2014

I have a JList<Object> in my code (it actually takes JLabels) called imageList, and I've given it a custom CellRenderer using the following code:

cellRenderer = new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public Component getListCellRendererComponent(JList<?> list,
Object value, int index, boolean isSelected,
boolean cellHasFocus) {

[Code] .....

However, when I click anywhere on the JList, nothing gets printed to the console, which suggests that the mousePressed() method isn't being invoked. I think it's a problem with the CellRenderer, because I have similar code elsewhere that works, the only difference being I don't use a custom CellRenderer.

View Replies View Related

Reading Json Of Nested Menu Without Giving Menu Names In Java

Aug 14, 2014

I want to read json file as follow;
 
{
  "M": {
  "row": [
  {
  "col1": "c00"
  },
  {
  "col1": "c10",
  "col2": "c11"
  },
  {
  "col1": "c20",
  "col2": "c21",
  "col3": "c22"
  }
  ]
  }
}
 
Next to reading I need to assign to two dimensional array, but without giving "col1","col2","col3" a lot. 

The array is for example, Array[3][] = {{"c00"},{"c10","c11"},{"c20","c21","c22"}};

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved