I recently encountered a scenario where attempting to set the text for an SWT TableColumn widget fails with an InvocationTargetException / SWTError and the message "Cannot set text". There is nothing special about the column text, i.e. no special characters or mnemonics. It just fails. The same code works for other scenarios.
I took a look at the SWT source for the TableColumn class and found only one place where the "Cannot set text" error is thrown - see code fragment below - but I cannot see why I should have encountered a problem.
/*
* Bug in Windows. When a column header contains a mnemonic character, Windows does not measure the text properly. This causes '...' to always appear at the end of the text. The fix is to remove mnemonic characters and replace doubled mnemonics with spaces.
*/
boolean replace = !OS.IsWinCE && OS.WIN32_VERSION <= OS.VERSION (4, 10);
long /*int*/ hHeap = OS.GetProcessHeap ();
TCHAR buffer = new TCHAR (parent.getCodePage (), fixMnemonic (string, replace), true);
int byteCount = buffer.length () * TCHAR.sizeof;
long /*int*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
OS.MoveMemory (pszText, buffer, byteCount);
lvColumn.mask |= OS.LVCF_TEXT;
lvColumn.pszText = pszText;
long /*int*/ result = OS.SendMessage (hwnd, OS.LVM_SETCOLUMN, index, lvColumn);
if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
if (result == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
I have a table column and I want to change the columns header justification from center justified to left justified. How do I do this, either via code or via CSS.
where itemName is a String identifying a different item for each column.
ItemCountFactory returns a StringBinding as the cell value, as follows:
public ObservableValue<String> call(CellDataFeatures<Category, String> rowData) { return new ItemCountBinding(rowData.getValue(), itemName); }
where class ItemCountBinding extends StringBinding { ... protected String computeValue() { String cellValue = ...; return cellValue; } }
The StringBinding depends on properties of the Category instance for the table row. The correct data is displayed okay, but I have noticed that every time one of the Category properties changes (i.e., every time a cell value changes), ItemCountFactory is called again to create a new StringBinding. I would have expected the Factory to be invoked just once for each cell during initialization, and then the table column would monitor the returned Observable object. Instead it seems to be creating a new Observable object every time the cell value changes. Is this normal, or am I doing something wrong? Same behavior on Java 8u20 and 8u40. If it is not the expected behavior, I will write an example test program; I do not want to post the current full source code.
The table items are set just once, with:
countTable.setItems(categoryList);
where categoryList is of type ObservableList<Category>. The list itself is not modified after being associated with the table; i.e., no rows are added or deleted or replaced.
I have a textField in which I have text in. The text is enter customer name. I would like for this text to disappear whenever the user clicks on the textField to enter a customer name. I am using the automated swing gui builder in NetBeans. Is their some sort of feature for this under properties of the text field? If not then what are my other options?
I'm working on a simple text editor, and I'm currently saving the contents of my JTextPane in a file using an HTMLEditorKit (text is a JTextPane):
private void save() throws IOException { int returnVal = fc.showSaveDialog(window); if (returnVal == JFileChooser.APPROVE_OPTION) { StyledDocument doc = (StyledDocument)text.getDocument(); HTMLEditorKit kit = new HTMLEditorKit(); BufferedOutputStream out;
[Code] ....
The problem I'm having is that after opening a file that I saved, it does not display (if I disable text/html, it displays the entire html code, but when I re-enable it, nothing displays at all.) Am I loading it wrong, or am I setting the JTextPane's text incorrectly? Or is it, perhaps, another error that I didn't catch?
I am building a chat server/client and would like to have it so when a user sends a message, the message pops up in the main chat area beside their name, which I would like to be in bold font. Something like "Alan: Hello, how are you?". I can't find a way to do this with a text area or on a string. Do any swing components suitable for use as text areas support bolding of certain sections of the string that you will set to it?
This shows a nice text area and an input field underneath it.The getGameHistory() method just returns a long string detailing the current game.Is there a way of just showing the text area without the input field underneath?Can the text area also be used for input instead?
I am in the middle of creating a chess application, and am currently working on laying out a list of moves on the right of the actual board. Specifically, I want to have a JLabel that says "moves" on top of a JList that contains the moves, on top of two buttons, labeled "<" and ">" respectively, to which I will eventually add functionality to take back and un-take back moves. Currently I have the first two parts down, but when I add my buttons,the other components are getting messed up.
I have all of these things in a vertical BoxLayout inside of a JPanel with a fixed width of 70, and a height that varies according to the size of the window (I overrode the getPreferredSize method of the JPanel). The two buttons are within their own JPanel with a grid layout with one row and two columns. Then I basically just add the moves list label, the movesList, and the panel housing the buttons to the larger panel, in that order.
However, I am encountering two problems. One, the buttons display the text "... " instead of "<" and ">" as if there is not enough room, although I'm pretty sure three periods take up more space than one less than or more than sign. The next is that, without the buttons at the bottom, the label reading "moves" is appropriately centered (or left aligned, I can't tell which) over the movesList, and you can read its whole text. However, when I add in the buttons at the bottom, the label of the top shifts over to the right and then reads "mov..." because it has run out of room.
Here is my code:
//move list movesListLabel = new JLabel("Moves"); //the components for the actual movesList come from another class with an object called pen, but I don't think this is the problem listModel = pen.getListModel(); JList movesList = pen.getMovesList(); JScrollPane listScroller = pen.getMovesListScrollPane();
I am using a JFrame with JPanel (with radiobuttons and jtextfields) and am wanting to get data from a text file (around 100 words) and input 4 words at a time into my gui. I have been trying to do this by filling an string array with the data, (no problems here) then using jTextField to read the array. (having a few problems in this area though) Am about 80% there...but just wondering is there a better way to approach this problem, that is, inputing words into gui, refreshing, input 4 new words, refreshing, etc.
If you print (eg a JTable) from Java/Swing and choose "Adobe PDF" as the printer, you get an Acrobat file. But the PDF isn't searchable because the text has already been rendered by Java before Adobe PDF gets to see it. Is there a way to make printing use a more high-level interface to the printer driver so that the text is left intact?
I am trying to write an application where if you click and hold down on 1 button and move the mouse to another button and release the text on the 2 buttons should be switched around.I have a print line so I can se the text are supposed to get switched around but it is just not happening in the GUI.
I attached all my code in case the flaw was to find somewhere else in the code, but the functionality I am working on is the lines 76 to 121.
Im writing a program that records the score in a dart game. One component of the program is a stage where players enter their name.This information needs to be displayed in another part of the program. These two components are in two different classes. My problem is I dont know how to get that information from one class to another.
Im using Jtextfield in Jframe to record the information.
Create a dnd (dungeons and dragons) character creator and back ground generator, have it display and run on a gui, to start with i decided to creator the gui as i go so i can see the progress, first i tried eclipse and windows builder, well after 1 day of reinstalling windows builder in about 5 different ways from multiple guides and sometimes getting it to partly work ...
After doing some more research I have figured out how to get the main program to display the gui . Heres what i have:
package com.mrgreaper; import javax.swing.*; public class MainWindow { private JPanel mainWindow; private JLabel playerlbl; private JLabel playerNamelbl;
[Code] .....
Now this works fine and the gui displays when the program is run but I can't change the text of any of the jlabels or textfield. If I try to do it in the main class i need to change them from private to public static but then in the form builder it says "cannot bind to static field *name of field*" but if i take static off then i cant change its value!
From what i understand this is because the window is an instance, so how to i change the value in that instance? I could put all my code in the one class, the one that creates the gui, but i really want it seperate, i would like the gui to update as the code runs... So how do i do it, how do i change the contents of jlabels on the fly, read the contents of text boxes on the fly etc....
I tried adding a getter setter
public void setCharFirst(JLabel charFirst) { this.charFirst = charFirst; } in the MainWindow.class
Then i tried to set it from my main function
MainWindow.setCharFirst("test");
but it cant access it as my main function is static and it is not now can i make it static...
This is the code that I wrote but I have two problem with two buttons one of them ... I want to delete the selected text inside the text Area which represented as b[8] and the other button that I want to select parts of the texts which represented as b[0]....
I am currently working on a project that can save text from a JTextArea and also open that same saved text. The problem I am having is that when I open the saved text file it is no longer formatted.
How the file looks before saving/closing:
public class HelloWorld{ System.out.println("Hello World!"); }
How the file looks after being saved/closed then opened:
public class HelloWorld{ System.out.println("Hello World!");}
When I save the file I'm actually saving the entire thing to a single string. When I do this the String eliminates all tabbed spacing and pushes all characters to one single line.
The only ideas I had for fixing this were to either somehow use Format in the String class or record every time user tabs and add to the String.
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
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.
I have two classes - One is Read.java and the other is Display.java
Read.java looks like this
public static void main(String[]args){ File file = new File("test.txt"); try{ FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr);
[Code] ....
Display.java looks like this:
public class Display extends JFrame { private JComboBox comboBox; private JPanel contentPane;
/** * Launch the application. */ public static void main(String[] args) { //method call to access other class
[Code] ....
Instead of having it so it displays the id's to the console,is there a way I can set it straight up to the combo box?
I want to create 3 JTextFields in a row with all being of equal size.But my first Text field gets so wide than the other two.After adding each component at a time and seeing what causes the problem I realized that if I type a long text for the JLabel that's when this problem occurs.If I reduce the length of the text in the JLabel JTextFields get into the sizes I want. Here's my code
import java.awt.*; import java.awt.event.*; import java.lang.Math; public class Calculator1 extends JFrame { JTextField value1=new JTextField("0"); JTextField value2=new JTextField("0");
[Code] ....
How can I stop the JTextFields changing size when I change the JLabel label1's text length...
I don't get what I missed in the code. I used the example of changing the text of a button by clicking on it, but instead I also added a JLabel and tried to make the button change its text instead, but it didn't work. What did I do wrong?
I have my below Swing GUI code in which I want to read and display some contents present in text file say (test.txt) which is located in my local disk (C: est.txt). My pane tab 2 is divided into two halves horizontally. How can I read and write the test.txt file contents under the tab tab2 in the first half of the pane(where currently it is 2 written)?
Sample test.txt present in my local hard disk location username:test1 Password:test1 DataBasename: testDB
CODE FOR TABBED PANE
import javax.swing.*; import java.awt.*; public class SplitPaneExp { public static void main(String[] args){ Runnable r = new Runnable() { public void run() { JFrame frame = new JFrame("WELCOME");
i just started java and I'm trying to change the JLabel text by clicking on the JButton however it isn't working,
import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JLabel; public class BorderLayoutJFrame extends JFrame { public static final int WIDTH = 400; public static final int HEIGHT = 400;
I have been going in circles trying to update a JTable. For now I just need to take input from a textfield after clicking on a JButton and have that text be placed in the JTable. LeftPanel listens, while RightPanel holds the table. Here is what I have so far: