| | |
Centering Issues
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2005
Posts: 177
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: 177
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...
| Thread Tools | Search this Thread |
-xlint add android api applet application array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component converter database digit eclipse equation error event exception fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying oracle page pearl print problem program programming project qt recursion scanner screen scrollbar server set size sms sort spamblocker sql string swing system thread threads time tree variablebinding windows xor





