I have a large JPanel which uses a GridBagLayout in which I put other JPanels inside the cells. The main JPanel is then added to a JScrollPane. What I'm looking to provide the user a way to automatically scroll to a particular item in the scrollable area (i.e. each of the child JPanels would represent - let's say a person for argument sake - and an user would like to click a button or bring that JPanel into focus / view.
The JPanels are added within a loop to the grid and references of these JPanels at the moment aren't store in an array or anything, so it's a case of being added and that's it. Also there's the case of where was the object exactly added and also how to have the scrollbar move to the proper focus location (both horizontally and vertically).
and the corresponding snippets of the Java code are:
// Class member variables // ... private String product; private ArrayList<String> productValues; private ArrayList<String> productLabels; private SelectItem[] products; // ... Various properties etc. public String getLocation() { // Displayed on a page
[code]....
Most of this works correctly using only ArrayList SelectItem products without the two ArrayList and the separate SelectItem[], and the values and labels are put directly into products here. The menu works and I can select an item. However, I am unable to find the correct method for finding the index in the submit method,namely:
public void submit(ActionEvent e) { showProduct = true; prodNum = products.indexOf(product); // --- Here is the problem! updateProduct(); }
which has not been changed here. In spite of trying out various ideas, prodNum always returns with -1, which means it cannot find the index of the selected product, where product is a String. Everything else seems to work correctly, and products.get(prodNum).getLabel() works if I manually give prodNum a valid index, but because it's -1 it fails.
I'm trying to use netbeans GUI creator to create a chessprogram. However, the default "freeflow" layout is very difficult to work with. However, when I switch the layout to gridbag or border layout, I can't figure out really how to do anything. I don't know how to resize or position elements. Any good set of tutorials for using netbeans GUI creator with non standard layouts?
(I originally used absolute layout, which I can easily add and position elements in, but which I abandoned because i want the chessboard squares to resize when the window changes size).
I am having a problem finding string objects in a jTable. I use setValueAt() to write string variables into a jTable.
I can then use getValueAt() to search to find any of those strings. All works fine until I edit an entry in the table. Then I can never find that string again.
In fact, if I just click in the cell type a character, then delete that character, something changes. The contents of the cell look the same but the search for it doesn't find it.
For example if I have a string "xyz" that was written in a cell. If I set the search value, "a=xyz", and "b=getValueAt(some cell)".
Then at the compare:
if(a==b) I can hover over a and b and I see that; a = (java.lang.String) xyz
and
b = (java.lang.String) xyz
[note I am using NetBeans to do this]
after the compare, the true path is taken .
If I then click in the cell then click out and try the same compare, everything is exactly the same including what gets reported when I hover. But the false path is taken at the "if".
I was wanting to select an item in a comboBox and display it in a text field but all it's doing at the minute is retrieving the first item in the comboBox and placing that in the txt field
String value = (String) comboBoxEnv.getSelectedItem().toString(); if(comboBoxEnv.getSelectedItem()!= null){ txtTo.setText(value);
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.
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?
I am developing a java based software connected with a mysql database. I have an Item table in my database. I created a bean class which can keep all item data with it and. Then I loaded each Item data in to its object and fill a Jcombobox. Now I want to search with Item name and get all Item data when selecting that item. I have overidden the toString method to Item name in that class. Is there any way to search my Item objects inside a jcombobox?
So I'm making a calculator using JFrame and that stuff and I need figuring out the GridLayouts. I'm not doing this for homework or anything just for fun. I don't need all the grid layouts.
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.
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.
I need to create dynamic Layouts that are created from java source code, using JAXB. As FXML does not have a schema, this gets me in trouble.
Scene Builder cannot be used for dynamic Layouts, but if there really is no schema I could use, maybe someone knows how Scene Builder generates the fxml files.
My problem occurs when I try to specify a file location as show below
//Open an output file that appends data and does not delete it FileWriter append_data=new FileWriter("C:hello.txt",true); //Make a file that cvan print data into it PrintWriter outputfile=new PrintWriter(append_data);
Apparently, I believe this is not the right way to set my own path for the file... How can I specify my file path.
One more question would be that suppose I want to specify the file location on Desktop. What the format for that?
I am writing a small app to automate some actions on my computer this requires me to open an application and click on a button I am using
Process child0 = Runtime.getRuntime().exec("/home/user/application");
to do this. The problem is every time it opens at a different lcation on the screen so i cannot click on it using the robot class due to x,y coordinates being different every time. with selenium you can use .setlocation(x,y) method but how can this be done for other applications.
As you can see instead of displaying the champion name it is displaying the memory location and I do not know how to fix it.
class Champions { String name; Champions [] weak = new Champions [3]; Champions [] strong = new Champions [3]; String [] items = new String [3]; public static void main (String [] args) {
I'm trying to copy a exe file from one location to another. It seems simple, but I have failed to find anything about it besides coping the contents in txt files, but that does nothing for executable.
For some reason my code returns the memory address of the array when its a print statement with a string, but it works fine when its in a separate print statement all by itself. Why? Do I need to create a toString method that converts a char array to a String to something? The reason why I ask that is becuase on Eclipse line 10 has a warning stating "Must explicitly convert char[] to a String".
public class Ex { private String word; public Ex(String word) { this.word = word; } public char[] Display(){ char[] wordChars = this.word.toCharArray(); return wordChars;
[Code] .....
Result:
Hello world The word is: [C@1db9742
I also tried this, knowing that it's a long shot, but that didnt do anything...
public String toString(){ Ex ex = new Ex(this.word); char[] word = ex.Display(); String updated = word.toString();//counter intuitive? return updated; }
The file (let's call it file.txt) is on the C: of my machine. I'm using :
System.out.print("Where is the file?: "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
And looking for the user to enter the location of the file in the console. How do I (the user) enter the path to the file in the console. I have tried everything... "C:file.txt", C:file.txt, and a million other combinations. Nothing seems to work. How does the console expect the file path to be written so it knows how to pick up the file?
I found a fun program online and something so simple is giving me an issue. I c++ it is pretty simple fix, I can just call the strings location like an array. In java this is not the case. So far i have tried:
myString.charAt(); myString.indexOf();
There are a few other I found on google but I forget at the moment. I am just trying to close the gap on a string. It was a full sentence and I used replaceAll a few times to get several words I didn't want in the file out.
My project was to create an array holding 10 integers and populate the array with 10 random numbers. Then ask the user to guess the number. Prompt the user with a while loop if their input is out of range. Determine if the users number is in the array, and display which index location the number is in. I got most of the code done but am having trouble displaying the index location.
import javax.swing.*; public class Homework4 { public static void main(String[] args) { int[] numarray = new int [10]; char repeatcode = 'y';