Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #28180 > unrolled thread
| Started by | rupertlssmith@googlemail.com |
|---|---|
| First post | 2014-04-22 07:50 -0700 |
| Last post | 2014-04-28 20:26 -0400 |
| Articles | 8 — 6 participants |
Back to article view | Back to comp.lang.java.programmer
Java Swing text as a grid? rupertlssmith@googlemail.com - 2014-04-22 07:50 -0700
Re: Java Swing text as a grid? markspace <markspace@nospam.nospam> - 2014-04-22 08:22 -0700
Re: Java Swing text as a grid? Jeff Higgins <jeff@invalid.invalid> - 2014-04-22 11:45 -0400
Re: Java Swing text as a grid? Jeff Higgins <jeff@invalid.invalid> - 2014-04-22 15:03 -0400
Re: Java Swing text as a grid? Rupert Smith <rupertlssmith@googlemail.com> - 2014-04-23 00:56 -0700
Re: Java Swing text as a grid? Roedy Green <see_website@mindprod.com.invalid> - 2014-04-23 19:49 -0700
Re: Java Swing text as a grid? Rupert Smith <rupertlssmith@googlemail.com> - 2014-04-25 02:13 -0700
Re: Java Swing text as a grid? Arne Vajhøj <arne@vajhoej.dk> - 2014-04-28 20:26 -0400
| From | rupertlssmith@googlemail.com |
|---|---|
| Date | 2014-04-22 07:50 -0700 |
| Subject | Java Swing text as a grid? |
| Message-ID | <8c3ea48c-26d5-4ef8-869b-08f46023b953@googlegroups.com> |
Hi, I'd like a text UI component that lets me place monospaced text within it, using row/column addressing. The built-in text controls are constructed around a Document model, which models text as a single stream (by stream I mean linear buffer of text), with rendered row/column derived from placement of newlines, wrapping strategy, and lots of other things. The Document model lets you have multiple root 'elements', each of which is a single stream. I'm thinking I could extend and existing text control, perhaps JTextArea, to render one root element per row, and disable all line wrapping. It might make more sense than having to insert newlines into the text stream to control row position. Does anyone have any thoughts on how to create a simple text grid UI control with Swing? I suppose I should take a look at lanterna, which must be achieving something similar to what I want, when emulating a console under Swing. Thanks for your input. Rupert Smith
[toc] | [next] | [standalone]
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Date | 2014-04-22 08:22 -0700 |
| Message-ID | <lj61gl$1fp$1@dont-email.me> |
| In reply to | #28180 |
On 4/22/2014 7:50 AM, rupertlssmith@googlemail.com wrote:
> Hi,
>
> I'd like a text UI component that lets me place monospaced text
> within it, using row/column addressing. The built-in text controls
I would just keep a separate structure, an array of lines, and then
index into that.
public class MyTextArray {
private JTextArea text = ...
private ArrayList<String> lines = ...
public void addText( String line ) {
lines.add( line );
text.add( line );
}
public char get( int row, int column ) {
if( row > lines.size() ) throw new IllegalArgumentException();
String s = lines.get( row );
if( column >= s.length() ) throw new IllegalArgumentException();
return s.charAt( column );
}
}
Flavor to taste.
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2014-04-22 11:45 -0400 |
| Message-ID | <lj62s5$buc$1@dont-email.me> |
| In reply to | #28180 |
On 04/22/2014 10:50 AM, rupertlssmith@googlemail.com wrote: > Hi, > > I'd like a text UI component that lets me place monospaced text within it, using row/column addressing. The built-in text controls are constructed around a Document model, which models text as a single stream (by stream I mean linear buffer of text), with rendered row/column derived from placement of newlines, wrapping strategy, and lots of other things. > > The Document model lets you have multiple root 'elements', each of which is a single stream. I'm thinking I could extend and existing text control, perhaps JTextArea, to render one root element per row, and disable all line wrapping. It might make more sense than having to insert newlines into the text stream to control row position. > > Does anyone have any thoughts on how to create a simple text grid UI control with Swing? I suppose I should take a look at lanterna, which must be achieving something similar to what I want, when emulating a console under Swing. > javax.swing.text is a big, and to my mind, complex package. <http://docs.oracle.com/javase/8/docs/api/javax/swing/text/View.html> Sorry I can't offer concrete suggestions.
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2014-04-22 15:03 -0400 |
| Message-ID | <lj6eet$66e$1@dont-email.me> |
| In reply to | #28184 |
On 04/22/2014 11:45 AM, Jeff Higgins wrote: > On 04/22/2014 10:50 AM, rupertlssmith@googlemail.com wrote: >> Hi, >> >> I'd like a text UI component that lets me place monospaced text within >> it, using row/column addressing. The built-in text controls are >> constructed around a Document model, which models text as a single >> stream (by stream I mean linear buffer of text), with rendered >> row/column derived from placement of newlines, wrapping strategy, and >> lots of other things. >> >> The Document model lets you have multiple root 'elements', each of >> which is a single stream. I'm thinking I could extend and existing >> text control, perhaps JTextArea, to render one root element per row, >> and disable all line wrapping. It might make more sense than having to >> insert newlines into the text stream to control row position. The key, I think, to working with the Swing text package is having your document model well sussed out before considering the views and controller. >> Does anyone have any thoughts on how to create a simple text grid UI >> control with Swing? I suppose I should take a look at lanterna, which >> must be achieving something similar to what I want, when emulating a >> console under Swing. You might look at the source of javax.swing.text.PlainView after you've got your document model completely worked out. > javax.swing.text is a big, and to my mind, complex package. > <http://docs.oracle.com/javase/8/docs/api/javax/swing/text/View.html> > Sorry I can't offer concrete suggestions. > >
[toc] | [prev] | [next] | [standalone]
| From | Rupert Smith <rupertlssmith@googlemail.com> |
|---|---|
| Date | 2014-04-23 00:56 -0700 |
| Message-ID | <3cc8ce8c-ee9c-430e-8c3d-efdf95bb7150@googlegroups.com> |
| In reply to | #28187 |
On Tuesday, April 22, 2014 8:03:25 PM UTC+1, Jeff Higgins wrote:
> On 04/22/2014 11:45 AM, Jeff Higgins wrote:
> You might look at the source of javax.swing.text.PlainView after
> you've got your document model completely worked out.
PlainView: The view represents each child element as a line of text.
Sounds like its pretty close to what I'm after, thanks.
> > javax.swing.text is a big, and to my mind, complex package.
Its a beast for sure. 6 chapters in the Swing text book I have, and even that doesn't leave room for the details.
I looked an lanterna and realised that rendering a simple grid of text can be as simple as implementing paintComponent()
for (int i = 0; i < columns; i++) {
for (int j = 0; j < rows; j++) {
graphics2d.drawString(characters[j][i], ...
So I think I will keep the model very simple for now, and render that way. I can re-implement on top of text.Document and play around with text.View as and when more capability is required.
Rupert
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-04-23 19:49 -0700 |
| Message-ID | <2rugl9tj85fg9ok4oucnapebf4lq4n44ur@4ax.com> |
| In reply to | #28180 |
On Tue, 22 Apr 2014 07:50:37 -0700 (PDT), rupertlssmith@googlemail.com wrote, quoted or indirectly quoted someone who said : > >Does anyone have any thoughts on how to create a simple text grid UI contro= >l with Swing? You could just have a GridBag layout of JTextAreas. Most fun is to do it the way you would in AWT with a Canvas (JPanel in Swing). See http://mindprod.com/products1.html#JDISPLAY for sample code. -- Roedy Green Canadian Mind Products http://mindprod.com "Don't worry about people stealing an idea; if it's original, you'll have to shove it down their throats." ~ Howard Aiken (born: 1900-03-08 died: 1973-03-14 at age: 73)
[toc] | [prev] | [next] | [standalone]
| From | Rupert Smith <rupertlssmith@googlemail.com> |
|---|---|
| Date | 2014-04-25 02:13 -0700 |
| Message-ID | <d1f48bad-ba8a-46ca-8cf9-121b99cfa42f@googlegroups.com> |
| In reply to | #28208 |
On Thursday, April 24, 2014 3:49:53 AM UTC+1, Roedy Green wrote: > >Does anyone have any thoughts on how to create a simple text grid UI > >control with Swing? > > You could just have a GridBag layout of JTextAreas. I hadn't thought of that. GridLayout I think you mean? with one character per grid cell. Would have been a quick and dirty way to get started. > Most fun is to do it the way you would in AWT with a Canvas (JPanel in > Swing). Looks like that is the route I am taking. :-) Rupert
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2014-04-28 20:26 -0400 |
| Message-ID | <535ef1b5$0$304$14726298@news.sunsite.dk> |
| In reply to | #28224 |
On 4/25/2014 5:13 AM, Rupert Smith wrote: > On Thursday, April 24, 2014 3:49:53 AM UTC+1, Roedy Green wrote: >>> Does anyone have any thoughts on how to create a simple text grid UI >>> control with Swing? >> >> You could just have a GridBag layout of JTextAreas. > > I hadn't thought of that. GridLayout I think you mean? Not necesarrily: http://docs.oracle.com/javase/7/docs/api/java/awt/GridLayout.html http://docs.oracle.com/javase/7/docs/api/java/awt/GridBagLayout.html GridBagLayout is a more flexible version of GridLayout. Arne
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web