I am using a JList in Java Swing, but when my Dialog opens, the List isn't shown.
private JList getJList() {
if (mylist == null) {
mylist = new JList();
mylist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
mylist.setSize(new Dimension(154, 106));
model.addElement("test");
model.addElement("zwei");
mylist.set...
I'm trying to display two pictures on my JFrame, the way I found was to use icons and JLabels, this seems pretty straightforward and I'm not having problems with this. But when it comes to locating the image I can't get it to work. I'm on a linux machine thus the forwardslash style. I created a folder called pics in my project which is c...
Hello,
I have a JPanel inside a JFrame. I have registered a KeyListener, based on which I want to update the JPanel. The problem I am having is that I cannot get the focus on the JPanel and therefore my KeyListener won't work. I already know that the KeyListener is functional because I registered it with the JFrame and it worked fine. M...
Hi everyone,
I'm writing a program that lets people highlight surfaces by dragging the mouse. (Just like the highlighted rectangles you can do make in most operating systems on the desktop).
Trouble is, what color should I use? I don't know of any color in UIDefaults that corresponds to the highlight color. SystemColor.controlHighlight ...
What's the best way to get a value of a TextArea after a key is typed, including this character?
If I do it in the even listener, textarea.getText() returns the value without the eventual new char.
Basically I see two ways:
postponing processing with something like invokeLater(). I would prefer a solution without threads.
figuring ou...
In my code, two comboboxes are added to actionListener( this );
In another part of my code, I call a combobox function that sets an index to a certain value. This in turn calls actionPerfoemed again and so getSource == comboBox is true. Every time I call a set function it calls actionPerformed again, creating a stack of function calls t...
If a JFrame has a JDialog modal open, the JDialog is animated (the borders and title bar have a lighter colour) if any other part of the application is clicked other than the JDialog with focus. The user is made aware of the window in focus to attend to first.
I have a Swing application with custom dialogs, setUndecorated(true) and cust...
Is there a way to limit a textfield to only allow numbers 0-100, thereby excluding letters, symbols and such as well? I have found a way, but it is way more complicated than seems necessary.
...
hi,
i'm using a JTextPane as a cell renderer in my table (so i can control color, font, size and links easily).
the problem is that lines get wrapped when the cell's get too small to contain the full text.
i know the number of expected text lines in advance (or i can just count), so i set the row's height accordingly.
how do i get the...
I have to two comboboxes, based on the selection made in the first combobox the selected value of the second box should change.
Please find the code snippet below:
secondcombobox.setSelectedItem(firstcombobox.getSelectedItem());
...
I want to have a JPanel which uses an image as a background, with this I want to add new panels to this panels so that they sit on top of this background image. I have tried the following:
Image background;
public Table(){
super();
ImageIcon ii = new ImageIcon(this.getClass().getResource("pokerTable.png"));
background = ii....
I am using an ObjectOutputStream to send a large object (possibly a Map) to the server using my Swing application, Is there anyway to monitor the percentage sent etc as in a file upload.
...
I'm currently using JTable to show the contents in database. I want to provide the facility for user so that he can select the number of rows he wants using shift+arrow key and then later on delete those records using the option provided for deletion. Please provide a small example.
...
I am making a card game where the cards are represented as JLabels, having names and some other attributes which are changed during the game. I want to define equality as simply comparing the full names (represented by a field fullName) of two cards. However, this gives me the problem that I can't add the same card twice (because I have ...
If you have a WindowListener, will a windowDeactivated(WindowEvent) event always occur whenever a window is closed, or is it possible for a windowClosing(WindowEvent) to occur without a windowDeactivated(WindowEvent) occurring. That is, is window deactivation a part of window closing?
Finally, will a windowClosed(WindowEvent) always (n...
I am using a GridBagLayout to (currently) display two rows. I am aware this layout is overkill for this task, but am trying to learn how to use it. The problem is that I have added the two panels to the two separate rows and there is a huge gap around the content (see image and code below):
Image background;
public Table(){
...
Some operating systems generate keyPressed events more quickly than my application can handle them. My first thought was to not perform the action if the calls are too close together, with something like this:
public void actionPerformed(ActionEvent e) {
long now = System.currentTimeMillis();
if(now - lastCall < 150) {
S...
Hi,
I'm having a JTable containing JComboBox editors initialized somewhat like
JComboBox comboBox = ...;
TableColumn tc = table.getColumnModel().getColumn(i);
tc.setCellEditor(new DefaultCellEditor(comboBox));
This is working otherwise fine but I'd like to be able to navigate in the table and update the values with keyboard only. Now...
Hello I'd like to get this swing layout inside a JPanel:
JLabel - JTextField - JComboBox
as the panel resizes I'd like the textField to expand but not the other two. Everything must remain in line. I tried grid bag layout but doesn't work... or I can't. Ideas?
...
I have a swing component: a JFrame in fact.
I noticed that when my code myframe.setVisible(flag); is executed it becomes invisible if flag is equal to false
and visible otherwise.
Does anybody know why?
...