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


ADVERTISEMENT

Swing/AWT/SWT :: Alternative To Null Layout

Aug 10, 2014

My IDE has a visual editor for creating Swing applications. The created application windows have no layout manager and use method "setBounds()" for placing Swing components on the application window. I have built an application that uses JInternalFrame. Each JInternalFrame is a separate and different "screen" for the user to interact with.

There are around 2,000 screens in the application and new screens are constantly being added as well as existing screens being modified. As a result, the top-level container - a JFrame - is a fixed size and is not resizable. I have now been asked to increase the size of the JFrame while maintaining the proportions of the screens.

Rather than manually editing the invocations of "setBounds()" on all the screens, any alternative way to achieve this? Also, is there a way to achieve this such that if, in future, the JFrame will again be resized, the screesn will automatically adjust?

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

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

Alternative To Update Passed Arguments?

Apr 22, 2015

I am writing a simple program in Java, where I call a method and pass some variables (namely, min and max) as arguments. This method is recursive, so the same arguments are again passed on in each recursive call.

I need to update these variables in recursive calls so that when the calling method uses them, it uses updated values. As it might sound confusing, here is sample code :

// Function 1.
void func1() {
//Call func2.
func2 (int hd, int min, int max, Map<String, String> map);
//Other stuff.
}
// Function 2.

[code]....

As you can see, min and max are updated after each recursive call returns, based on conditions. However, these changes aren't reflected in original min and max, which were used by func1 while calling func2. As far as I know, this happens due to call by value mechanism being used by Java while passing arguments. If I declare min and max as instance variables in the class, my problem is solved. But, I want to know whether there's any other way to update these variables so that changes in original min and max are reflected. Yes, I can return them as an array of 2 elements each time while returning, but it didn't seem a good solution to me.

View Replies View Related

Swing/AWT/SWT :: AffineTransform Making Image To Move

Aug 5, 2009

I've been trying to make an image rotate in a panel. I did it. But also i want the image to make a translation.

Here is the code i tryed at paintComponent() :

//////////////////////////

Graphics2D g2 = (Graphics2D) g ;
AffineTransform at = new AffineTransform() ;
// at.rotate ( angle in radians ) ;
at.rotate( this.getAngulo(1, 1) ) ;
g2.drawImage(imgemFlecha, at, this);
/////////////////////////////

I cant change image x,y doing this drawImage(). I want to make that change.

View Replies View Related

Swing/AWT/SWT :: Making GUI Application Design Extensible

May 5, 2015

I have to create a Swing application for which i haved a set of requirements as,

1. there will be two JPanels ,left and right, on the main JFrame , left frame would contain a JTextField and a submit JButton ,user can enter values 1,2,3 ,in the JTextField and presses the JButton

a. if user enters 1, a JTextField will be shown on right JPanel
b. if user enters 2, a JTextField and a JRadioButton will be shown on right JPanel
c. if user enters 3, a JTextField and a JComboBox will be shown on right JPanel

So I have done that but when my boss sees the code behind this application he told me to make it more extensible i.e. if there is going to be an additional requirement for values 4 or 5 or 6 and so on , then i have to make minimal changes in my code or no change in my code and it should work . how this can be done ? is it possible make such software design ?

public class DesktopApp extends JFrame {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(DesktopApp.class);
private JPanel jp, jp2, mainPanel;
private JLabel jl, jl1, jl2, jl3, jl4, jl5;
private JTextField jText, jText2, jText3, jText4;

[Code] ....

What wrong am i doing here in this code which in not considered to be an extensible design ?

View Replies View Related

Swing/AWT/SWT :: Making Ball Bounce Around A Screen

Aug 12, 2014

I've got to make a ball bounce around a screen.... From what I can gather they seem to hold back useful java code.

anyway, i've changed the code over and over, and think this is the most succinct way i can manage it. but i have a problem. where i've marked the code (*****) and the following line are conditional on each other. so one won't provide the correct answer without the other line executing first, and vice versa (ignore the code after, i haven't looked at where that should be yet ). Anyway I don't really want to rip the code apart, again, because i'm pretty sure it's close.

View Replies View Related

Swing/AWT/SWT :: Making Interface - Exception Group Layout

Sep 24, 2014

I am making an expert system using Jess about animals. I wanted to make an interface using Swing and so I did. I have a problem using group layouts. The application works fine but at the end a exceptions is thrown:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,
alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,
preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,
horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,
text=The animal is a cheetah.,verticalAlignment=CENTER,
verticalTextPosition=CENTER] is not attached to a horizontal group

[Code] ....

The application ask the user some questions about the animal. When the expert system has enough information to know the animal it tells the name of the animal and shows a picture of it. The exception is thrown when the application has guessed the animal and shows the response.

Here is the code:

package xindria;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.GroupLayout.SequentialGroup;
import java.awt.*;
import java.awt.event.ActionEvent;

[Code] .....

I think the problem is related to the group layouts. I will attach the eclipse project too...

View Replies View Related

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

Swing/AWT/SWT :: Making Two JComboboxes To Be In Sync When One Selects Item From Dropdownlist?

Jan 17, 2015

basically I would like to know how to to the following Java. Example... Say I have one JComboBox, and it is populated with 10 items which reads from a text file ("apple","banana","kiwi","orange","grape fruit"), and the other JComboBox holds the price ($1,$2,$4, etc etc...you get the drift).

How do I make in such a way when I select for example banana from the JCombobox that it syncs the other JCombox to the correct price?

Basically syncing the two JCombobox so that you do not need to select the price yourself - it does it automatically for you.

View Replies View Related

Swing/AWT/SWT :: Making A Tetris Clone - How To Get Cube To Visualize In JPanel

Nov 10, 2014

My question is, how do I get my Cube to visualize in the JPanel? I've tried a bunch of add methods but they don't compile. Is there a proper method I can use to add an object to a JPanel?

import javax.swing.*;
import java.awt.Dimension;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.*;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Making JButton That Switches Text From 2 JTextFields On Click With Mouse

Aug 6, 2014

I have made a window using JFrame and on my JPanel I have added 3 components: 2 JTextFields ("field1" and "field2") and inbetween them a JButton ("switch"). My goal is to switch the value of field1 to field2 and vice versa when the JButton is clicked. I thought this ActionListener which I have added to my JButton would achieve my goal:

public void actionPerformed(ActionEvent e) {
field2.setText(field1.getText());
field1.setText(field2.getText());
}

However, it changes the value of field2 into the value of field1 but not the other way around.

View Replies View Related

Swing/AWT/SWT :: How To Add Setbounds Inside Static Void Main In Java

Dec 31, 2014

I am making an application in java, inside static void main, i want to customize all buttons, text areas and want to put them on desired location inside application. I have tried to use setbounds but can not use it, how can i use it, or is there any other way or layout to make my application components customized layout.

View Replies View Related

Swing/AWT/SWT :: Making Flipbook In Java Similar To Flash Flipbook

Mar 16, 2012

Is there a way to create a flipbook using swings similar to flash flipbook.

View Replies View Related

Servlets :: Cannot Make Static Reference To Non-static Method GetQuery From Type Resource

Mar 26, 2015

This is my code inside the method:

@Post
public static String getDetails(Representation entity) throws Exception {
String customerId = getQuery().getValues("cus_id");
}

I use this code in Restlet Representation. I try to get the value from the Request API. But I am facing the problem as "Cannot make a static reference to the non-static method getQuery() from the type Resource".

View Replies View Related

Can Static Method Return Instances Of Same Class In Special Case Where Everything Is Static?

Jun 27, 2014

From what i understand static methods should be called without creating an instance of the same class . If so why would they return an instance of the same class like in the following : public static Location locateLargest(double[][] a) , the Location class being the same class where the method is defined . I don't understand this , does it mean that every field and every method in the class must be static ? Meaning that you cannot have instances of the class because everything is static . Or it's just a mistake and the class Location cannot have a static method: public static Location locateLargest(double[][] a) ?

View Replies View Related

Update User - Cannot Make Static Reference To Non-Static Method

Apr 26, 2015

I can't figure out what this error message "Cannot make a static reference to the non-static method getEndUserCharge(long, long, long, long) from the type UpdateUserWS" actually means.

The error is coming from:

public void updateDetailsPackage() {
some unrelated code
long zero=0;
double endUserCharge=0;
endUserCharge = UpdateUserWS.getEndUserCharge(long zero, long zero, long zero, long zero); <-------- error is here

[Code] ....

View Replies View Related

Player Class - Cannot Make Static Reference To Non-static Method

May 26, 2015

Alright, I have two classes, this one

public class Player {
private String player;
public String getPlayer() {
return player;
}
private int strength;
private int defense;

[Code] .....

However, it says that under Player.getPlayer() that it 'Cannot make a static reference to the non-static method'.

View Replies View Related

Instantiating Class With Non Static Variables From Within Static Method

Oct 28, 2014

Why I can create an Instance of a class that contains non static variables within the static main method ?

This program runs fine

import java.util.*;
public class Test{
public int j;
public static void main(String[] args) {
Test test1=new Test();
System.out.println(test1.j);

[Code] .....

View Replies View Related

Non-static Variable Cannot Be Referenced From Static Context - Error

Mar 15, 2015

I am trying to call an actionListener which is shown below in my PSVM :

class testMenuItemListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
getContentPane().removeAll();
createPanel();
getContentPane().add(panel1); //Adding to content pane, not to Frame
repaint();
printAll(getGraphics()); //Extort print all content

[Code] .....

I get the following error :

Frame.java:409: error: non-static variable this cannot be referenced from a static context
menuItem1.addActionListener(new testMenuItemListener());

View Replies View Related







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