Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #23514 > unrolled thread
| Started by | clusardi2k@aol.com |
|---|---|
| First post | 2013-04-19 16:54 -0700 |
| Last post | 2013-04-20 14:14 -0400 |
| Articles | 9 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
5th col dies, cols 6 thru 15 move 1 col left, 15th col is born clusardi2k@aol.com - 2013-04-19 16:54 -0700
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born Knute Johnson <nospam@knutejohnson.com> - 2013-04-19 17:03 -0700
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born "clusa@aol.com" <clusardi2k@aol.com> - 2013-04-19 17:29 -0700
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born "clusa@aol.com" <clusardi2k@aol.com> - 2013-04-19 22:29 -0700
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born Knute Johnson <nospam@knutejohnson.com> - 2013-04-20 09:02 -0700
[OT] Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born Manuel Collado <m.collado@domain.invalid> - 2013-04-20 16:44 +0200
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-20 11:17 -0400
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born "clusa@aol.com" <clusardi2k@aol.com> - 2013-04-20 09:02 -0700
Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-20 14:14 -0400
| From | clusardi2k@aol.com |
|---|---|
| Date | 2013-04-19 16:54 -0700 |
| Subject | 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born |
| Message-ID | <300a4c2f-daba-4007-8551-3b1d0f263d27@googlegroups.com> |
What is the best way to build the following application. I would like to create an application that when it opens it will have 300 rows and 15 columns. The first 4 columns on the left side will be updated with alphanumeric data but will always be displayed. They never disappear. The remaining 11 columns (also containing alphanumeric data) will move to the left with the leftmost column (column 5) disappearing and a brand new column 15 will appear on the right side of the window. Column 15 never existed before. Again, I want an application with 15 columns always displayed with the 5th column leaving (data not saved) the application, columns 6 through 15 will move one column to the left, and the 15th column will be populated with new data. What's the best way to do this. Do you have example code for me. Thank you,
[toc] | [next] | [standalone]
| From | Knute Johnson <nospam@knutejohnson.com> |
|---|---|
| Date | 2013-04-19 17:03 -0700 |
| Message-ID | <kkslq8$bf9$2@dont-email.me> |
| In reply to | #23514 |
On 4/19/2013 4:54 PM, clusardi2k@aol.com wrote: > What is the best way to build the following application. > > I would like to create an application that when it opens it will have > 300 rows and 15 columns. > > The first 4 columns on the left side will be updated with > alphanumeric data but will always be displayed. They never > disappear. > > The remaining 11 columns (also containing alphanumeric data) will > move to the left with the leftmost column (column 5) disappearing and > a brand new column 15 will appear on the right side of the window. > Column 15 never existed before. > > Again, I want an application with 15 columns always displayed with > the 5th column leaving (data not saved) the application, columns 6 > through 15 will move one column to the left, and the 15th column will > be populated with new data. > > What's the best way to do this. Do you have example code for me. > > Thank you, > Are these data entry fields? Or just to be displayed? Probably just drawing the data on a JComponent would be the easiest and quickest but would take a little more effort to create. JLabels are nice too. -- Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | "clusa@aol.com" <clusardi2k@aol.com> |
|---|---|
| Date | 2013-04-19 17:29 -0700 |
| Message-ID | <7470ee0c-3435-4625-8b04-bd555387f0d8@googlegroups.com> |
| In reply to | #23515 |
On Friday, April 19, 2013 8:03:06 PM UTC-4, Knute Johnson wrote: > Are these data entry fields? Or just to be displayed? Probably just drawing the > data on a JComponent would be the easiest and quickest but would take a little > more effort to create. JLabels are nice too. -- Knute Johnson No, the data in the cols comes from files. The user does not enter the data. Thank you,
[toc] | [prev] | [next] | [standalone]
| From | "clusa@aol.com" <clusardi2k@aol.com> |
|---|---|
| Date | 2013-04-19 22:29 -0700 |
| Message-ID | <428f2f7d-32a7-4c66-8451-8ad7e04b87ec@googlegroups.com> |
| In reply to | #23515 |
> On Friday, April 19, 2013 8:03:06 PM UTC-4, Knute Johnson wrote: > Are these data entry fields? Or just to be displayed? Probably just drawing the > data on a JComponent would be the easiest and quickest but would take a little > more effort to create. JLabels are nice too. -- Knute Johnson So, you suggest to use a JComponent with (300 x 15) JLabels. Why would using a JComponent be better than using a JFrame containing JPanels. With a JComponent, will I be able to easily change the color of the JLabels. I guess I should use a Layout also. I was planning to have the columns move left after N seconds. Are there any other details that I should worry about such as flicker. Thanks,
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <nospam@knutejohnson.com> |
|---|---|
| Date | 2013-04-20 09:02 -0700 |
| Message-ID | <kkue0h$5j1$1@dont-email.me> |
| In reply to | #23517 |
On 4/19/2013 10:29 PM, clusa@aol.com wrote:
>> On Friday, April 19, 2013 8:03:06 PM UTC-4, Knute Johnson wrote:
>> Are these data entry fields? Or just to be displayed? Probably just drawing the
>> data on a JComponent would be the easiest and quickest but would take a little
>> more effort to create. JLabels are nice too. -- Knute Johnson
>
> So, you suggest to use a JComponent with (300 x 15) JLabels.
>
> Why would using a JComponent be better than using a JFrame containing JPanels.
>
> With a JComponent, will I be able to easily change the color of the JLabels.
>
> I guess I should use a Layout also.
>
> I was planning to have the columns move left after N seconds.
>
> Are there any other details that I should worry about such as flicker.
>
> Thanks,
>
No, what I was suggesting was that you draw your data on the JComponent,
or JPanel if you want, rather than use components as it will render much
quicker and you can do a fade in/out or change colors when you move your
data pretty easily. It would be easier to scale as well.
import java.awt.*;
import java.awt.event.*;
public class test extends JComponent implements Runnable {
private static final String text = "Now is the time for all good
men to " +
"come to the aid of their country. The quick brown fox jumped
over the " +
"lazy red dog. Four score and seven years ago our fathers brought
forth" +
"on this continent a new nation conceived in liberty and dedicated
to " +
"the proposition that all men are created equal.";
private final String[][] words = new String[6][6];
private volatile int n;
public test() {
setPreferredSize(new Dimension(400,300));
String[] array = text.split(" ");
for (int i=0; i<6; i++)
for (int j=0; j<6; j++)
words[i][j] = array[n++];
n = 0;
setFont(new Font("Monospaced",Font.PLAIN,10));
}
public void paintComponent(Graphics g) {
g.setColor(Color.YELLOW);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(Color.BLUE);
for (int cols=0; cols<6; cols++)
for (int rows=0; rows<6; rows++)
g.drawString(words[cols][rows],10+60*cols,20+15*rows);
}
public void run() {
while (true) {
++n;
repaint();
try {
Thread.sleep(5000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
String[] temp = new String[6];
for (int i=0; i<6; i++)
temp[i] = words[2][i];
for (int i=2; i<5; i++)
for (int j=0; j<6; j++)
words[i][j] = words[i+1][j];
for (int i=0; i<6; i++)
words[5][i] = temp[i];
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
test t = new test();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(t,BorderLayout.CENTER);
f.setSize(400,300);
f.setVisible(true);
new Thread(t).start();
}
});
}
}
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Manuel Collado <m.collado@domain.invalid> |
|---|---|
| Date | 2013-04-20 16:44 +0200 |
| Subject | [OT] Re: 5th col dies, cols 6 thru 15 move 1 col left, 15th col is born |
| Message-ID | <kku9jb$rfg$1@speranza.aioe.org> |
| In reply to | #23514 |
El 20/04/2013 1:54, clusardi2k@aol.com escribió: > What is the best way to build the following application. > > I would like to create an application that when it opens it will have > 300 rows and 15 columns. > > The first 4 columns on the left side will be updated with alphanumeric > data but will always be displayed. They never disappear. > > The remaining 11 columns (also containing alphanumeric data) will move > to the left with the leftmost column (column 5) disappearing and a brand > new column 15 will appear on the right side of the window. Column 15 > never existed before. > > Again, I want an application with 15 columns always displayed with the > 5th column leaving (data not saved) the application, columns 6 through > 15 will move one column to the left, and the 15th column will be > populated with new data. > > What's the best way to do this. Do you have example code for me. If your input and output data are just text files you could consider using awk instead of Java. -- Manuel Collado - http://lml.ls.fi.upm.es/~mcollado
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2013-04-20 11:17 -0400 |
| Message-ID | <kkubde$jhq$1@dont-email.me> |
| In reply to | #23514 |
On 4/19/2013 7:54 PM, clusardi2k@aol.com wrote:
> What is the best way to build the following application.
>
> I would like to create an application that when it opens it will have 300 rows and 15 columns.
>
> The first 4 columns on the left side will be updated with alphanumeric data but will always be displayed. They never disappear.
>
> The remaining 11 columns (also containing alphanumeric data) will move to the left with the leftmost column (column 5) disappearing and a brand new column 15 will appear on the right side of the window. Column 15 never existed before.
>
> Again, I want an application with 15 columns always displayed with the 5th column leaving (data not saved) the application, columns 6 through 15 will move one column to the left, and the 15th column will be populated with new data.
>
> What's the best way to do this. Do you have example code for me.
JTable should be straightforward. You'd extend AbstractTableModel
to handle the "sliding," calling fireTableDataChanged() to update the
display. Conveniences like scrolling would come for free (almost),
and the JTable's display might well be more efficient than managing
4500 JLabels.
No, I don't have example code.
--
Eric Sosman
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | "clusa@aol.com" <clusardi2k@aol.com> |
|---|---|
| Date | 2013-04-20 09:02 -0700 |
| Message-ID | <98b6f34a-4162-472a-a740-91e86c1b3217@googlegroups.com> |
| In reply to | #23525 |
> On Saturday, April 20, 2013 11:17:52 AM UTC-4, Eric Sosman wrote: > JTable should be straightforward. You'd extend AbstractTableModel to handle > the "sliding," calling fireTableDataChanged() to update the display. > Conveniences like scrolling would come for free (almost), and the JTable's > display might well be more efficient than managing 4500 JLabels. No, I don't > have example code. -- Eric Sosman esosman@comcast-dot-net.invalid I would also be able to eloquently color specific cells. Thanks
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2013-04-20 14:14 -0400 |
| Message-ID | <kkulp2$v0f$1@dont-email.me> |
| In reply to | #23528 |
On 4/20/2013 12:02 PM, clusa@aol.com wrote:
>> On Saturday, April 20, 2013 11:17:52 AM UTC-4, Eric Sosman wrote:
>> JTable should be straightforward. You'd extend AbstractTableModel to handle
>> the "sliding," calling fireTableDataChanged() to update the display.
>> Conveniences like scrolling would come for free (almost), and the JTable's
>> display might well be more efficient than managing 4500 JLabels. No, I don't
>> have example code. -- Eric Sosman esosman@comcast-dot-net.invalid
>
> I would also be able to eloquently color specific cells.
You can be as eloquent as you like with a TableCellRenderer,
most likely an extension of DefaultTableCellRenderer. This time,
I've got some example code (not eloquent, and not colorized, but
it should demonstrate the approach):
/**
* A {@code TableCellRenderer} that centers displayed text.
*/
class CenteredRenderer extends DefaultTableCellRenderer {
private static CenteredRenderer instance;
static CenteredRenderer instance() {
if (instance == null) {
instance = new CenteredRenderer();
}
return instance;
}
private CenteredRenderer() {
assert SwingUtilities.isEventDispatchThread();
}
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean select, boolean focus, int row, int col) {
assert SwingUtilities.isEventDispatchThread();
Component comp = super.getTableCellRendererComponent(table,
value, select, focus, row, col);
if (comp instanceof JLabel) {
((JLabel) comp).setHorizontalAlignment(SwingConstants.CENTER);
}
return comp;
}
}
I use it this way, in the constructor of a class extending
JTable:
TableColumnModel colmod = getColumnModel();
for (int c = 0; c < COLUMNS; ++c) {
TableColumn col = colmod.getColumn(c);
if ( /* I want this column centered ... */ ) {
col.setCellRenderer(CenteredRenderer.instance());
}
}
--
Eric Sosman
esosman@comcast-dot-net.invalid
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web