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


ADVERTISEMENT

Swing/AWT/SWT :: Making A Custom Cell Renderer Work In A JTable?

Jan 24, 2014

Now my issue is I have a JTable. The first column will contain Date objects all the way to the bottom. I want the JTable to display only the month and year. I created a custom cell renderer, but it appears the cell renderer method "getTableCellRendererComponent" is never called. (I tested it using System.out.println();) Here is my code for setting the cell renderer and the contents of the first column:

MonthYearTableCellRenderer renderer = new MonthYearTableCellRenderer();
tblView.setDefaultRenderer(Date.class, renderer);
for(int i = 0; i < 60; i++){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.add(Calendar.MONTH, i);
tableModel.setValueAt(cal.getTime(), i, 0);
}

The Date objects are set into the cells of column 0 correctly. The table shows the result of the "toString()" method for each cell in that column.

View Replies View Related

Working With Custom JList Component In Java

Aug 21, 2014

I am trying to use the JList to display a list of students. Now, each student has a first name, last name and course taken. each courses taken by the student has its' own name, level and idNumber. For now, I am just trying to create my own custom JList model for the students. I have the custom model as well as the button event calling it. Unfortunately, when I click the button to display the student info added, the component is NOT fired up!..

I am not sure what I have done wrong regarding creating the component because I can display the information on the console and the list contains everything I have added but just to display it on the component is NOT working. I have broken the codes into sub classes, you can add the classes to the same package or create sub packages to insert individual classes.

The student class
 
public class Student {
 private String studentName;
private String studentID ;
 public String getStudentName(){
return studentName;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Same Code For Both ActionListener And MouseListener

Mar 8, 2014

is any simple way to apply the same code on both ActionListener and MouseListener, so that the same code is executed when the user either presses a JButton or presses Enter when a JTextField is focused.I know that I can define a method, while it is not preferred as I may use break; in my MouseListener.

A simple example:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TwoListener extends JFrame
{

[code]....

Although I can define a new method that prints out the three numbers, I have to add certain break; code in different cases. So I just wonder whether there is another way to do things like this.

View Replies View Related

Swing/AWT/SWT :: JMenu - Is This OK To Use MouseListener Over ActionListener

Aug 13, 2014

I know that JMenu and JMenuItem is suppose to use action listeners but would you consider this implementation an exception?

menuAbout.addMouseListener (new MouseListener () {
@Override
public void mouseClicked (MouseEvent arg0) {
JOptionPane.showMessageDialog (null, "Server Tec Software System
}
@Override
public void mouseEntered (MouseEvent arg0) { }
@Override
public void mouseExited (MouseEvent arg0) { }
@Override
public void mousePressed (MouseEvent arg0) { }
@Override
public void mouseReleased (MouseEvent arg0) { }
});

View Replies View Related

Search Form Doesn't Work

Feb 18, 2014

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class frmSearch extends JDialog
{
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
JPanel jpnlMain = new JPanel();

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Changing Rectangle Color With MouseListener

Mar 2, 2014

I'm trying to build a program which sets a fill color for a rectangle. Each time the mouse is clicked the fill color changes according to the position of the mouse's X and Y. I succeeded to create a JFrame with a changing background according to the Mouse's position, but I can't seem to change the color of the rectangle (defined in MyPanel class).

This is the current code,

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;

[Code]...

View Replies View Related

JavaCV Drawing Convexhull Doesn't Work

Sep 9, 2014

import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import com.googlecode.javacv.cpp.opencv_core.CvMemStorage;
import com.googlecode.javacv.cpp.opencv_core.CvPoint;
import com.googlecode.javacv.cpp.opencv_core.CvScalar;
import com.googlecode.javacv.cpp.opencv_core.CvSeq;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_highgui.CvCapture;
import com.googlecode.javacv.cpp.opencv_imgproc.CvMoments;

[code]....

Everything works in this except the part where drawing a convexhull and the convexitydefects around an object. Drawing circle around the COG works OK. I tried to draw them with these lines but no luck.

hullSeq = cvConvexHull2(bigContour, hullStorage, CV_COUNTER_CLOCKWISE, 0);

defects = cvConvexityDefects(bigContour, hullSeq, defectsStorage);

cvDrawContours(img1,defects , CvScalar.BLUE, CvScalar.BLUE, 1,0,0);

cvDrawContours(img1,hullSeq , CvScalar.BLUE, CvScalar.BLUE, 1,0,0);

View Replies View Related

KeyListener Doesn't Work - Button Is Not Displayed

Apr 14, 2015

Why the keyTyped function isn't triggered, when i type a key?

Here is my code:

package main;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
 
[Code] .....

I have noticed, that if i call setVisible(true) before i add the button, then it works, but the button is not displayed... How can i achieve that the button is displays AND the KeyListener works?

View Replies View Related

ReadLine Doesn't Work - Cannot Find Symbol

Oct 10, 2014

int arabe = Integer.readLine(args[0]);
String romain= "";

The compilator says that it can't find symbol. The arrow is under the "".""

It worked before.

View Replies View Related

HTTP KeepAlive Seems Doesn't Work With Java

Jun 10, 2015

I have java http client which sends periodically (every 30 sec; this code is run by heartbeat thread in the cycle) heartbeats:
 
private PostResponse post(String jSessionCookie, final String action, final String data, final int postTimeoutMs) throws IOException, SSYSException
{          
final HttpURLConnection httpConn = openHttpUrlConnection(true, postTimeoutMs, jSessionCookie);
final OutputStream os = httpConn.getOutputStream();
try (final PrintWriter wr = new PrintWriter( DefaultProperty.isEnableSocketTraceGW ? new TracerOutputStream(os) : os ))

[Code] .....
 
On the server side there is Tomcat 8.0.21 + APR connector. Every time this heartbeat is sent I see in the Wireshark and EtherDetect that new TCP connection is opened (SYN-SYNACK packets) and after getting response from Tomcat connection is closed (FIN – FINACK packets). I was expecting that TCP connections will be reused but not closed.

Capture.png 182.0 K

View Replies View Related

Populating Array Doesn't Work Inside Constructor

Feb 24, 2014

Java Code:

import java.io.*;
import java.util.Scanner;
public class asciiFile {
int height;
int width;
Scanner input;
char[][] poop;
public asciiFile(File f) throws FileNotFoundException{ //constructor

[code]...

The constructor is supposed to take an ASCII file, take the numbers in the file, and populate a 2D array with the numbers in the file.

For some reason, the for loop I use to populate the array works outside of the constructor. When I put it in one of the methods, it runs normally. However, when I keep it in the constructor, I get the following error:

Exception in thread "main" java.lang.NullPointerException

at asciiFile.<init>(asciiFile.java:16)

at main.main(main.java:6)

View Replies View Related

Works In Netbeans / Eclipse But Doesn't Work After Being Compiled By Either

Mar 2, 2014

There is a specific function I have added to a program I've been working with for a while which involves retrieving data from a website. Here is that code:

Java Code: public String getWebData(String urlString, String add) throws IOException{
String output = "";
try {
//+s being the token, for example if dictionary.com was being used
add = add.replace(" ", "+s");
urlString = urlString + add;
URL url = new URL(urlString);
InputStream inputStream = url.openStream();

[code]....

Anyway, when I run this program within Netbeans, it works perfectly. I have a backup of the project in eclipse as well, and I've copied all of the code over and tried running the same thing in Eclipse - exactly the same, it works perfectly. The problem is whether I compile the the code in Netbeans or Eclipse, the exported runnable jar for some reason has an issue with this one method. It doesn't crash, and it seems to be doing something, but it is by no means giving me the data from the website like it is supposed to.

View Replies View Related

Code That Works On Fiddle But Doesn't Work On Local

Oct 9, 2014

I have this code: [URL] .... It works on fiddle but on local it does not work. What should be the problem?

Fiddle:

$('#addnewline').on('click', function (e) {
e.preventDefault();
var $textarea = $('#thetext');
$textarea.val(function () {
return $(this).val().substring(0, this.selectionstart) + "<br>" + $(this).val().substring(this.selectionstart);
});
});
<button id="addnewline">New line</button>
<br />
<textarea rows="4" cols="50" id="thetext">Some text

View Replies View Related

JSP :: Searching Data Using NON English Language Words Doesn't Work

Oct 30, 2014

Below is my code

<%--
Document : closeAc
--%>
<%@page import="javax.swing.JOptionPane"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*, java.util.Date;"%>
<%
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");

[code]....

All I'm trying to do is to search the data from the database and is doesn't show up!

View Replies View Related

Read XML File And Delete Its Contents - Boolean Doesn't Appear To Work

Oct 17, 2014

I'm trying to read a xml file and delete it's contents. I do this by reading the file,writing it to a temp and then overwriting the original with the temp by renaming it

//overwrite original xml file with new file
boolean successful = outputFile.renameTo(inputFile);
System.out.println("success");

It does say the value of the local variable is not used however. I've debugged to ensure it hits the code it always prints out the line after too.It just does not overwrite my original xml file with the temp one.

It's had votes on stack so I thought that would of been reputableStack - overwrite but the second one got voted as a good answer. But still I would like to know if my code can work or not.

View Replies View Related

Simple If Statement Taking A String Input Doesn't Work

Jun 6, 2014

Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
if (input == "next") {
System.out.print("good Job!");
}
else {
System.out.println("Why ?");
}

//If I type in next it prints out "Why ?" instead of "Good Job!" - Why though ?

View Replies View Related

Servlets :: Setting Httponly Programmatically In Cookies Doesn't Seem To Work

Nov 5, 2014

I am using servlet 2.4 I used the ff. code below to set httponly in my application's cookies but it did not work. When I do a javascrip alert (document. cooke) in my page, the session id still shows up.

Cookie [] cookies = request.getCookies();
for(int x=0; x<cookies.length; x++){
Cookie cookie = (Cookie) cookies[x];
String cookieValue = cookie.getValue();
cookie.setValue(cookieValue + "; HttpOnly");
}

I also tried doing this and it wouldn't work too

String sessionid = request.getSession().getId();
response.setHeader("SET-COOKIE", "JSESSIONID=" + sessionid + "; HttpOnly");

by the way I am using an application server with its JAVA EE version = 1.4 and JAVA SE version = 5

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

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

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 :: 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

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

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 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

Swing/AWT/SWT :: Stuck With A Custom TableModel?

Feb 2, 2015

I am trying to make a custom table for a DB and i am stuck.

I want only the first column to have a checkbox and others not.

Is there a better way to insert the values instead using the getValueAt ?

@Override
public Object getValueAt(int row, int col)
{
if (col == 0)

[Code].....

View Replies View Related







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