| | |
Centering Issues
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2005
Posts: 180
Reputation:
Solved Threads: 0
I'm toying around with Java trying to familiarize myself with the basic GUI stuff. I can't get my program or my text field inside of it to center on the screen.
For the Simple... file, I've tried using the and
seperately. When I have either of them as active code and not comments, it throws an error and won't even run the program. What am I missing here?
For the Simple... file, I've tried using the
Java Syntax (Toggle Plain Text)
theTextArea.setLocation(15, 30);
Java Syntax (Toggle Plain Text)
//theTextArea.setAlignmentX(CENTER_ALIGNMENT); //theTextArea.setAlignmentY(CENTER_ALIGNMENT);
Java Syntax (Toggle Plain Text)
//mainForSimpleGUI.java import javax.swing.*; import java.awt.*; public class mainForSimpleGUI { public static void main(String[] args) { SimpleJavaGUI labelFrame = new SimpleJavaGUI(); //creates SimpleJavaGUI //labelFrame = new JLabel(); labelFrame.setLocationRelativeTo(null); labelFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); labelFrame.setSize(300, 300); labelFrame.setVisible(true); } }
Java Syntax (Toggle Plain Text)
//SimpleJavaGUI.java import java.awt.*; import javax.swing.*; public class SimpleJavaGUI extends JFrame { private JTextArea theTextArea; public SimpleJavaGUI() { super("mainForSimpleGUI"); setLayout(new FlowLayout() ); theTextArea.setLocation(15, 30); //theTextArea.setAlignmentX(CENTER_ALIGNMENT); //theTextArea.setAlignmentY(CENTER_ALIGNMENT); theTextArea = new JTextArea(2, 20); theTextArea.setText(" Follow the white rabbit."); theTextArea.setToolTipText("This is a text area."); theTextArea.setEditable(false); theTextArea.setDisabledTextColor(Color.BLACK); theTextArea.setLineWrap(true); theTextArea.setBorder(BorderFactory.createLineBorder(Color.black) ); add(theTextArea); } }
Be what you is, don't be what you ain't.
Cause if you ain't what you is, you is what you ain't!
Cause if you ain't what you is, you is what you ain't!
•
•
Join Date: Sep 2005
Posts: 180
Reputation:
Solved Threads: 0
Okay, I changed that. For whatever reason, it's not showing the text area at all now. Here's how it looks now (I commented out any location-oriented lines just to try and "dumb" it down and figure out why my text area vanished):
Java Syntax (Toggle Plain Text)
//SimpleJavaGUI.java import java.awt.*; import javax.swing.*; public class SimpleJavaGUI extends JFrame { private JTextArea theTextArea; public SimpleJavaGUI() { super("mainForSimpleGUI"); setLayout(new FlowLayout() ); theTextArea = new JTextArea(2, 15); theTextArea.setLocation(50, 50); //theTextArea.setAlignmentX(CENTER_ALIGNMENT); //theTextArea.setAlignmentY(CENTER_ALIGNMENT); theTextArea.setText(" Follow the white rabbit."); theTextArea.setToolTipText("This is a text area."); theTextArea.setEditable(false); theTextArea.setDisabledTextColor(Color.BLACK); theTextArea.setLineWrap(true); theTextArea.setBorder(BorderFactory.createLineBorder(Color.black) ); add(theTextArea); } }
Be what you is, don't be what you ain't.
Cause if you ain't what you is, you is what you ain't!
Cause if you ain't what you is, you is what you ain't!
•
•
Join Date: Jul 2007
Posts: 108
Reputation:
Solved Threads: 7
Java Syntax (Toggle Plain Text)
import javax.swing.*; import java.awt.*; public class mainForSimpleGUI { public static void main(String[] args) { SimpleJavaGUI labelFrame = new SimpleJavaGUI(); labelFrame = new SimpleJavaGUI(); labelFrame.setLocationRelativeTo(null); labelFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); labelFrame.setSize(300, 300); labelFrame.setVisible(true); } } @SuppressWarnings("serial") class SimpleJavaGUI extends JFrame { public JTextArea theTextArea; public SimpleJavaGUI() { super("mainForSimpleGUI"); setLayout(new FlowLayout() ); theTextArea = new JTextArea(2, 20); theTextArea.setLocation(15, 30); theTextArea.setAlignmentX(CENTER_ALIGNMENT); theTextArea.setAlignmentY(CENTER_ALIGNMENT); theTextArea.setText(" Follow the white rabbit."); theTextArea.setToolTipText("This is a text area."); theTextArea.setEditable(false); theTextArea.setDisabledTextColor(Color.BLACK); theTextArea.setLineWrap(true); theTextArea.setBorder(BorderFactory.createLineBorder(Color.black) ); add(theTextArea); } }
![]() |
Similar Threads
- Centering DIVs inside CSS (HTML and CSS)
- Centering a form in VB.NET (VB.NET)
- ASP.NET and Mozilla - Issues! (ASP.NET)
- SuSE 9.1 - Minor issues (*nix Software)
- Error messages, Taskbar changes in XP + USB connectivity issues. (Windows NT / 2000 / XP)
- Login issues (Web Browsers)
- Mail apps issues - error port 25 (Mac Software)
- Security Issues (*nix Software)
- Graphics Card issues Stop Command??? (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: Best Approach ?
- Next Thread: Something's missing...
Views: 233 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database detection draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linux list loop map method methods mobile netbeans newbie number object objects oracle oriented os panel print problem program programming project projects recursion replaydirector reporting researchinmotion return robot rotatetext scanner screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows





