Animated table of strings - java

I'm trying to write a scorekeeping app in Java that allows a server application to send scores to client applications. The clients will then display a list of teams, team IDs and their scores, sorted by score. Of course I could just use a swing JTable to display everything, but I want to achieve a unique effect: I want the text dynamically reorder itself every time a team moves up in the list. That is, it want to animate the text around the screen. I would also need to be able to update the contents of the labels after being added. What would be the best way to achieve this? Is there any component that allows you to add other components to it and place/move them freely?

JTable is a JComponent so you can set desired LayoutManager and add JLabels above the JTable. Then move/reorder them to achieve desired effect. See SwingWorker as well.

You could use a JTable and change the contents of the rows as teams move up. Or you could arrange a series of labels and change the text whenever you want. To change the value displayed for a JLabel you simply use the JLabel.setText("new value"); method.
I've never done this but I think you need to use a panel with a 'null' layout manager. Meaning you are responsible for absolutely positioning your elements
http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html
You would need some kind of SwingWorker or Timer running to update the gui layout. Make sure you actually make the GUI changes on the EventThread, which you can do by using SwingUtilities.invokeLater();

As alternatives to a null layout, consider letting the layout work for you using
one of the marquee effects discussed here, or
shuffling labels in a suitable layout, shown here and here.

Related

What GUI component should I use?

I am working on my homework assignment and I have to achieve the following layout. Can anyone guide me as to how to achieve the right side of the view? I have already coded the left part, it's just the right side that I don't know what to use?
Calendar GUI
Should I just use paintComponent or a JTable?
JTable doesn't seems to suit your needs. You can consider using an array of JTextArea which will be added into a JScrollPane.
In this case, you can make use of the existing behaviours from these JComponents, such as setting them as editable/non-editable. Auto scrolling for JTextArea. JTextArea also allows displaying of multiple lines of records.
Should I just use paintComponent
I supposed you meant by custom painting. Using custom painting will give you alot of freedom to do your own customizations, however if the current JComponents are able to fulfill you needs, then I think you shouldn't try to reinvent the wheel, especially when you need to deal with printing text. Aligning the text properly in custom painting could cost you alot more time than learning how to use various existing JComponents.

Java - Placing of few buttons and textboxes using SWT

I need to place few buttons one under another and few textboxes in the same way using SWT.
When I'm doing that, they are next to each other and I cannot change it even using
button1.setLocation(new Point(100,20));
button2.setLocation(new Point(400,10));
Can I add those things to something similiar to SWING's JPanel and move/position it freely as I need? Or maybe another solution? As to let You know - I cannot use SWING here. It has to be SWT. The reason is that I have already a chart made with SWT. The buttons and textboxes should be placed so they won't be covering my chart.
You can dynamically add a new control to the existing layout, but make sure you call the layout() on the parent Composite, where you have set the layout.
If you want to place a SWT control relative to another control, you can use org.eclipse.swt.layout.FormLayout.

What is this component name

What is the name of the component in java Swing shown in the following link
http://www.scriptocean.com/template3.html
It is known as extended ListView in Android. But I want to know the same in Java Swing.
Do you mean this component ?
If so, to display it in Java, you have some choices.
If you want your items to be easily clickable (that's to say action senders), you would tend to use JButtons in a vertical BoxLayout 'ed JPanel
If you simply want to display items, then customize their display, you would undoubtly go the JList way. Also take a look at Swing tutorial, which is always of great help.
EDIT
Accordint o comment, to have an area below the button displaying content, you'll use the second solution with a twist. As all elements in Swing are in fact JComponents and can be put in thers, you'll use JPanel as JList elements. in each JPanel, you'll have ione button always visible and one sub-panel that is hidden at startup. When clicking the JButton, you'll simply show or hide the associated sub-panel. If you want to have some kind of effect, you can either
wait for the upcoming JavaFX transitions effects
Use Filthy Rcih Clients animations library (take a look at their links page).
There is no standard Swing component that behaves like in your example. But you can find something similar in the SwingX project : the JXTaskPane and JXTaskPaneContainer components.
Unlike your example, the sections are not exclusive. But you can achieve this exclusivity with a few lines of code.

Java Swing group of Jbuttons without raised portion

I wanted to know how to display a group of JButtons to look like smooth panel without raised portion.
thanks
button.setBorder(null);
You may want to look at some of the other "setXXX" method that control painting as well.
I've often just used standard JLabels and added mouseListeners to make them clickable. Alternatively, you could get more advanced and create your own ButtonUI class if you want to really fine-grained control over the rendering of the buttons.
If you want the buttons to be in a row, you can put them in a JToolBar and set Rollover to true. This will make flat buttons that, with mouse over, look raised.

In Java Swing how can you manage a list of panels allowing multiple panels to be selected?

I’m working on an in-house app that tracks a bunch of tasks. I wanted to have a simple task monitor that would list the task name and the task’s status. I need this to look just a little nice, I’m no designer so whatever I do is going to suck, but a basic text display won’t work for the project requirements.
What I am essentially attempting to do is show something similar to the Firefox download window, the I-Tunes download window, and well I could name more but they all look basically the same. In each of these apps, each of the ‘progress panels’ is selectable. So to implement this I thought it would be simple to just use a list of JPanels each with a JProgressBar and a JLabel, each of which can just accept focus to determine if it and others are selected. I thought this was going to be an easy task, but if I use a JList it just displays text. I then just figured I would show all the task panels in a larger panel, but I cannot get the inner panels to recognize focus.
Is there a pattern for this? Is there a rolled standard solution that I just have not found? Or is there a better method for doing this? I don’t want to re-invent the wheel, but I thought this was just going to be simple.
It sounds like what you may be looking for is an JList.
You can add your items to the JList's by first adding your "task" to the JList object's ListModel (see the Create a Model section from The Java Tutorials), and then you'll want to assigned a custom ListCellRenderer which will accept your "task" and render on the JList as a JPanel in the list itself. The key here is to make your custom ListCellRenderer be able to display your "task" in the JList the way you want to have it show on the JList.
Take a look into the Writing a Custom Cell Renderer section from the How to Use Lists page of The Java Tutorials. It will describe how to make your custom ListCellRenderer so you can represent your "task" as anything you want.
To keep it short, you will implement the ListCellRenderer interface by implementing the getListCellRendererComponent which will return a Component which is the representation of your task in the JList. You'll probably want to either construct or instantiate your JPanel in this method and return it as the Component.
The standard way of doing this kind of things is to use JTable (or JList) as a container.
You don't have to use default renderes fot table cells, but you can specify your own renderer for specific cells. Take a look at CellRenderer
How about a JTable (which you can set to allow multiple rows to be selected) with an internal JPanel occupying the single cell in each row, which contains a JProgressBar and a JLabel. Or you could use a JList with the same structure as I just described.

Categories