Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  UI Problems, scrollpane issues  (Read 1109 times)
0 Members and 1 Guest are viewing this topic.
Offline jyang81

Junior Newbie




Java games rock!


« Posted 2003-12-13 20:21:49 »

Hi, I made a scrollable JTextArea that receives strings from a JTextField that I made. It works like a chat window so that when you enter text in the field, it goes straight to the text area. The UIWindow I made has the exact format as the Xith3DGuiTest.java TestWindow. When I add text to the JTextArea, I can't scroll down and look at the text. When I place the cursor in the JTextArea, I can use the arrow keys to move down and up, but it screws up the character graphics. Please help!
Here is my code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
ackage oos.ui;

import java.awt.*;
import java.awt.event.*;

import oos.utils.*;

import com.xith3d.scenegraph.*;
import com.xith3d.render.*;
import com.xith3d.render.jogl.*;
import javax.vecmath.*;
import javax.swing.*;

import com.xith3d.image.*;
import com.xith3d.loaders.texture.*;
import com.xith3d.userinterface.*;
import com.xith3d.userinterface.UIWindowManager;
import com.xith3d.userinterface.UIWindow;
import com.xith3d.userinterface.UIEventAdapter;

/**
 * @author Jonghwan Andrew Yang
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */

public class TryUI{
      UIWindowManager windowMgr;
      View view;
      String inputText = "";


      public void init() throws Exception
            {
                  // Prepare full-screen canvas adapted for current resolution
                 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

                  VirtualUniverse universe = new VirtualUniverse();
                  view = new View();
                  view.setBackClipDistance(100f);
                  view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
                  view.getTransform().lookAt(
                        new Vector3f(0, 0, 3),
                        new Vector3f(0, 0, 0),
                        new Vector3f(0, 1, 3));
                  Locale locale = new Locale();
                  universe.addLocale(locale);
                  universe.addView(view);

                  RenderPeer renderPeer = new RenderPeerImpl();
                  CanvasPeer canvasPeer =
                        renderPeer.makeCanvas(
                              null,
                              screenSize.width - 200,
                              screenSize.height - 200,
                              16,
                              true);
                  canvasPeer.getWindow().setLocation(100, 100);
                  Canvas3D canvas = new Canvas3D();
                  canvas.set3DPeer(canvasPeer);
                  view.addCanvas3D(canvas);

                  // construct a window manager for this canvas

                  windowMgr = new UIWindowManager(canvas);
                  TestWindow w = new TestWindow(1000,150);
                  windowMgr.addOverlay(w);
                  windowMgr.setPosition(w,100,690);
                  windowMgr.setVisible(w,true);
                 
           
                 
                  UIEventAdapter eventAdapter = new UIEventAdapter(windowMgr);
                  canvas.get3DPeer().getComponent().addKeyListener(eventAdapter);
                  canvas.get3DPeer().getComponent().addMouseListener(eventAdapter);
                  canvas.get3DPeer().getComponent().addMouseMotionListener(eventAdapter);
                  canvas.get3DPeer().getComponent().setFocusable(true);

                  //BranchGroup scene = new Scenegraph();
                 //locale.addBranchGraph(scene);
                 view.startView();

            }
     
      class TestWindow extends UIWindow{

            public TestWindow(int width, int height) {
                  super(width, height, false, false );
                        setRoot(buildGUI(width,height));
            }

            private JComponent buildGUI (int width, int height) {
                  JSplitPane pane;
                  JPanel p = new JPanel();
                  p.setDoubleBuffered(true);
                  p.setSize(new Dimension(width,height));
                  p.setLocation(0,0);
                  p.setBackground(new Color(.7f,.7f,.7f,0.5f)); //the 4th parameter changes the transparency setting
                 p.setLayout(new GridLayout(3,1));

           
                 
                  //scrollable text area that can't be edited and displays the text that chat people can read
                 final JTextArea textAreaScreen = new JTextArea();
                  textAreaScreen.setEditable(false);
                  textAreaScreen.setBackground(new Color(1f,0,0,.5f));
                  textAreaScreen.setLineWrap(true);
                  JScrollPane scrollPaneScreen = new JScrollPane(textAreaScreen);
                  p.add(scrollPaneScreen);
                 
                  //this is the text field that allows someone to write something so that it can be put in the scrollable
                 //text area.
                 final JTextField textFieldInput = new JTextField();
           
                  textFieldInput.setBackground(new Color(1f,0,0,1f)); //the 4th parameter changes the transparency settings
                 textFieldInput.addKeyListener(new KeyListener(){

                        public void keyPressed(KeyEvent e) {
                             
                        }

                        public void keyReleased(KeyEvent e) {
                             
                        }

                        public void keyTyped(KeyEvent e) {
                             
                              //this notices when 'enter' is pressed and the string in the text field should be sent to the
                             //text area for everyone to see when chatting
                             if(e.getKeyChar() == 10){
                                    inputText = inputText + "\n" + textFieldInput.getText();
                                    System.out.println(inputText);
                                    textFieldInput.setText("");
                                   
                                    textAreaScreen.setText("");
                                    textAreaScreen.setText(inputText);
                                   
                              }            
                             
                        }
                 
                  });
                  p.add(textFieldInput);

                  //adds an exit button to quit the program
                 JButton logoutButton = new JButton();
                  logoutButton.setPreferredSize(new Dimension(100,100));
                  logoutButton.setText("Logout");
                  logoutButton.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                                    System.exit(0);
                        }
                  });      
                  p.add(logoutButton);

                  return p;
                 
            }
           

      }
     
      public static void main(String[] args)
            {
                  System.out.println("Hit SPACE to toggle projection policy, or ESC to exit");
                  try
                  {
                        TryUI test = new TryUI();
                        test.init();
                  }
                  catch (Exception e)
                  {
                        e.printStackTrace();
                  }
      }
}
Offline DavidYazel

Junior Member




Java games rock!


« Reply #1 - Posted 2003-12-13 21:04:07 »

You need to add a listener on the scrollbar and force a redraw of the scrollpane.

Like this:

1  
2  
3  
4  
5  
            skinScrollPane1.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
                    public void adjustmentValueChanged(AdjustmentEvent e) {
                        skinScrollPane1.repaint();
                    }
                });

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline endolf

JGO Knight


Medals: 7
Projects: 1


Current project release date: sometime in 3003


« Reply #2 - Posted 2003-12-14 19:01:32 »

Hi
 Do I need to do something like this to get highlighted text in a text area/text field, currently the cursor moves, but does't visibly redraw, but hitting delete or summat shows the whole lot being deleted as if it was highlited?, I am fully ready to admit I don't know swing this deeply Smiley

Endolf

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline shochu

Junior Member




Java games rock!


« Reply #3 - Posted 2003-12-15 02:07:55 »

Mabye add a CaretListener and listen for careUpdate events.  When you get a caret update event do a repaint on the text area?

That's what I would try at least.  Are your scroll panes working?  My scroll pane buttons aren't working as I posted previoulsy here http:// http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=xith3d;action=display;num=1071447510

If you get your scroll pane buttons and slider working please let me know how you did it.  Thanks =)

Also,  I tried jyang81's code above adding the fix David mentioned and I noticed that the textinput panel is transparent as should be but the textarea isn't.  

Did you guys have this problem too?  It seems both of them should be the same color right?  ANyone know how to fix this because I'm sure I will run into the problem soon.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (63 views)
2014-04-15 18:08:23

BurntPizza (61 views)
2014-04-15 03:46:01

UprightPath (74 views)
2014-04-14 17:39:50

UprightPath (57 views)
2014-04-14 17:35:47

Porlus (74 views)
2014-04-14 15:48:38

tom_mai78101 (100 views)
2014-04-10 04:04:31

BurntPizza (160 views)
2014-04-08 23:06:04

tom_mai78101 (255 views)
2014-04-05 13:34:39

trollwarrior1 (208 views)
2014-04-04 12:06:45

CJLetsGame (215 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!