Results 1 to 13 of 13
Like Tree3Likes
  • 1 Post By DarrylBurke
  • 1 Post By Fubarable
  • 1 Post By Fubarable

Thread: These components should at least TRY to look decent

  1. #1
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default These components should at least TRY to look decent

    I've been rassling (kind of like wrestling, but with more "attitude") with getting my form to look more like Miss Universe than Miss Piggy.

    I'm to the point where I'd settle with just getting the JTextFields and JTextAreas to back off the edges of the form a little. The JButtons and JLabels are offset to the right a little bit, but those JTextFields and JTextAreas insist on clinging tenaciously to the sides of the pool. I'd like the *Tex* to align with the Buttons and Labels.

    What will it take to render them extraordinarily?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    EmptyBorder. And please post GUI related questions in the appropriate forum. Moving this thread.

    db
    blackbird likes this.

  3. #3
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Quote Originally Posted by DarrylBurke View Post
    EmptyBorder. And please post GUI related questions in the appropriate forum. Moving this thread.

    db
    Been there, done that, doesn't work:

    Java Code:
    taSent.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by blackbird View Post
    Been there, done that, doesn't work:

    Java Code:
    taSent.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    It works fine for me.

    Please understand though that "doesn't work" tells us less than squat. What exactly are you trying to achieve? How doesn't this tool work? How did you try to use it? What was the expected vs. observed behavior? Why not create and post a minimal code example that we can compile, run, test, and modify (an SSCCE)? Why not post images of what is happening vs. what you want to have happen?

    In other words, if you still need our help, consider helping us help you by giving us sufficient information to be able to understand your problem.
    camickr likes this.

  5. #5
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    It works fine for me.

    Please understand though that "doesn't work" tells us less than squat. What exactly are you trying to achieve? How doesn't this tool work? How did you try to use it? What was the expected vs. observed behavior? Why not create and post a minimal code example that we can compile, run, test, and modify (an SSCCE)? Why not post images of what is happening vs. what you want to have happen?

    In other words, if you still need our help, consider helping us help you by giving us sufficient information to be able to understand your problem.
    I simply want:
    (a) to put some space around the controls, so they don't cling to each other like pre-teens at a horror flick
    (b) to move the JLabels a little to the right, away from the extreme left side of the form

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default

    Quote Originally Posted by blackbird View Post
    I simply want:
    (a) to put some space around the controls, so they don't cling to each other like pre-teens at a horror flick
    (b) to move the JLabels a little to the right, away from the extreme left side of the form
    And how did an empty border not help with that? What did it do instead? What layout(s) are you using? Again, an SSCCE would help more than a description.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    And how did an empty border not help with that? What did it do instead? What layout(s) are you using? Again, an SSCCE would help more than a description.
    It did absolutely nothing / had no effect whatsoever. I'll work on a Super Sexy Cheetah Chow Envelope.

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default

    Quote Originally Posted by blackbird View Post
    It did absolutely nothing / had no effect whatsoever. I'll work on a Super Sexy Cheetah Chow Envelope.
    Yeah, it sounds like a problem with your layout (or lack thereof), or you weren't using a thick enough border. Seeing some code will clear things up.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Here's my bad java gui; I will post soon my desired Java GUI (cobbled together with Visual Studio)

    If you can't see it (I can't), you can at http://warbler.posterous.com/bad-java-gui

  10. #10
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Here's the better java gui (I would definitely settle for this)

    The top pic is the better/preferred layout (mockup created with Visual Studio in five minutes); the bottom one is as it exists (Java).

    I will post the pertinent (GUI-related) code next.

  11. #11
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Quote Originally Posted by blackbird View Post
    I will post the pertinent (GUI-related) code next.
    Don't want folks thinkin' that I'd lie:

    Java Code:
    ...
    	// =====================================================================
    	// Components
    	JPanel mainPanel;
    	JTextArea taSent;
    	JTextArea taReceived;
    	JTextField tfIPAddr; 
    	JLabel lblIPAddr;
    	JTextField tfDispatchPort;
    	JLabel lblDispatchPort;
    	JTextField tfDispositionPort;
    	JLabel lblDispositionPort;
    	JLabel lblSent;
    	JLabel lblReceived;
    	JButton btnOpenDispatchFile;
    	JLabel lblDispatchFileName;
    	JButton btnOpenDispositionFile;
    	JLabel lblDispositionFileName;
    	JButton btnSendReceiveAndStop;
    	JLabel lblTimerInterval;
    	JTextField tfTimerInterval;
    
    	public RT_TCP_JCP_TDS_OO_State_SortSim() {
    	}
    
    	public static void main(String[] args) {
    		new RT_TCP_JCP_TDS_OO_State_SortSim().go();
    	}
    
    	public void go() {
    		JFrame frame = new JFrame("JCP TDS RT TCP Util (AKA 'Fred')");
    		mainPanel = new JPanel();
    		mainPanel.add(Box.createRigidArea(new Dimension(10, 0)));
    
    		// The "Sent" (contents from file[s]) TextArea
    		taSent = new JTextArea(TEXT_AREA_ROWS, TEXT_AREA_COLS); // rows, columns
    		taSent.setLineWrap(true);
    		taSent.setWrapStyleWord(true);
    		taSent.setEditable(false);
    		taSent.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    		JScrollPane qScrollerSent = new JScrollPane(taSent);
    		qScrollerSent
    				.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    		qScrollerSent
    				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    
    		// The "Received" (contents from remote machine) TextArea
    		taReceived = new JTextArea(TEXT_AREA_ROWS, TEXT_AREA_COLS);
    		taReceived.setLineWrap(true);
    		taReceived.setWrapStyleWord(true);
    		taReceived.setEditable(false);
    		JScrollPane qScrollerReceived = new JScrollPane(taReceived);
    		qScrollerReceived
    				.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    		qScrollerReceived
    				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    
    		btnSendReceiveAndStop = new JButton(START_CAPTION);
    		btnSendReceiveAndStop.addActionListener(new SendButtonListener());
    		btnOpenDispatchFile = new JButton(OPEN_DISPATCH_FILE);
    		btnOpenDispatchFile
    				.addActionListener(new OpenDispatchFileButtonListener());
    		btnOpenDispositionFile = new JButton(OPEN_DISPOSITION_FILE);
    		btnOpenDispositionFile
    				.addActionListener(new OpenDispositionFileButtonListener());
    
    		tfIPAddr = new JTextField(16);
    		tfIPAddr.setText(JAYAS_IP_ADDR);
    		tfIPAddr.setMaximumSize(new Dimension(TEXT_FIELD_WIDTH, TEXT_FIELD_HEIGHT));
    		lblIPAddr = new JLabel("Remote IP Address:");
    		lblIPAddr.setPreferredSize(new Dimension(32, 32));
    		lblIPAddr.setPreferredSize(new Dimension(32, 32));
    
    		lblDispatchPort = new JLabel("Dispatch Port:");
    		lblDispatchPort.setPreferredSize(new Dimension(32, 32));
    
    		tfDispatchPort = new JTextField(4);
    		tfDispatchPort.setText(Integer.toString(PORT_1));
    
    		lblDispatchFileName = new JLabel("Dispatch File Name = ");
    		lblDispatchFileName.setPreferredSize(new Dimension(32, 32));
    
    		lblDispositionPort = new JLabel("Disposition Port:");
    		lblDispositionPort.setPreferredSize(new Dimension(32, 32));
    
    		tfDispositionPort = new JTextField(4);
    		tfDispositionPort.setText(Integer.toString(PORT_2));
    
    		lblDispositionFileName = new JLabel("Disposition File Name = ");
    		lblDispositionFileName.setPreferredSize(new Dimension(32, 32));
    
    		lblSent = new JLabel("Sent");
    		Font bigFont = new Font("Verdana", Font.PLAIN, 24);
    		lblSent.setFont(bigFont);
    		lblReceived = new JLabel("Received");
    		lblReceived.setFont(bigFont);
    		
    		tfDispatchPort.setMaximumSize(new Dimension(TEXT_FIELD_WIDTH, TEXT_FIELD_HEIGHT));
    		tfDispositionPort.setMaximumSize(new Dimension(TEXT_FIELD_WIDTH, TEXT_FIELD_HEIGHT));
    		lblTimerInterval = new JLabel("Timer Interval in Milliseconds (Dispatch will be this val - 200 MS, Disposition will be this val + 200 MS)");
    		tfTimerInterval = new JTextField(Integer.toString(iTimerInterval));
    		tfTimerInterval.setMaximumSize(new Dimension(TEXT_FIELD_WIDTH, TEXT_FIELD_HEIGHT));
    
    		mainPanel.add(lblIPAddr);
    		mainPanel.add(tfIPAddr);
    
    		mainPanel.add(lblDispatchPort);
    		mainPanel.add(tfDispatchPort);
    		mainPanel.add(btnOpenDispatchFile);
    		mainPanel.add(lblDispatchFileName);
    
    		mainPanel.add(lblDispositionPort);
    		mainPanel.add(tfDispositionPort);
    		mainPanel.add(btnOpenDispositionFile);
    		mainPanel.add(lblDispositionFileName);
    
    		mainPanel.add(btnSendReceiveAndStop);
    		mainPanel.add(lblTimerInterval);
    		mainPanel.add(tfTimerInterval);
    		mainPanel.add(lblSent);
    		mainPanel.add(qScrollerSent);
    		mainPanel.add(lblReceived);
    		mainPanel.add(qScrollerReceived);
    
    		mainPanel.setBackground(Color.LIGHT_GRAY);
    
    		frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
    		mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
    
    		frame.setSize(630, 840); 
    		frame.setLocationRelativeTo(null); 
    		frame.setVisible(true);
    	}
    	// . . .
    }
    Last edited by blackbird; 07-26-2011 at 06:48 PM. Reason: To prevent Liechtenstein from cornering the market on snake-skin boots

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by blackbird View Post
    It did absolutely nothing / had no effect whatsoever. I'll work on a Super Sexy Cheetah Chow Envelope.
    Then you're using it wrong, simple as that. Don't blame the screwdriver when you're trying to use it as a hammer. We don't want the "pertinent" GUI code, we don't want all your code. Again, post an SSCCE, and we'll be able to help you. Read the link please and it will tell you what you need to create and post here.

    Edit: hell, you're adding the empty border to the JTextArea, so no wonder it's not "working". Again if we can play with compilable runnable code, a small demo SSCCE GUI, we can better help you.

    For example, this is like an SSCCE, but is a little bit longer so as to show a GUI like yours. Note that it has no functionality and the JTextFields and JTextAreas are not usable, but it does demonstrate using layouts and using borders, which is its sole purpose:

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    
    @SuppressWarnings("static-access")
    public class SscceEg {
       private static final int DEFAULT_INSET = 8;
       private static final float TAP_LABEL_SIZE = 24f;
    
       public static void main(String[] args) {
          JPanel topPanel = new JPanel(new GridBagLayout());
          int ebGap = 10;
          topPanel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder(
                      BorderFactory.createEtchedBorder(), "Top Panel"),
                BorderFactory.createEmptyBorder(ebGap, ebGap, ebGap, ebGap)));
    
          GridBagConstraints gbc;
    
          gbc = getGBC(0, 0);
          topPanel.add(new JLabel("IP Address"), gbc);
          gbc = getGBC(1, 0);
          topPanel.add(new JTextField(10), gbc);
          gbc = getGBC(2, 0);
          topPanel.add(new JLabel("Timer Interval", SwingConstants.RIGHT), gbc);
          gbc = getGBC(3, 0);
          topPanel.add(new JTextField(10), gbc);
    
          for (int i = 0; i < 4; i++) { // empty row
             gbc = getGBC(i, 1);
             topPanel.add(new JLabel(""), gbc);
          }
    
          gbc = getGBC(0, 3);
          topPanel.add(new JLabel("Dispatch Port"), gbc);
          gbc = getGBC(1, 3);
          topPanel.add(new JTextField(10), gbc);
          gbc = getGBC(2, 3);
          topPanel.add(new JButton("Open Dispatch Port"), gbc);
          gbc = getGBC(3, 3);
          topPanel.add(new JLabel(), gbc);
    
          for (int i = 0; i < 2; i++) { // empty row
             gbc = getGBC(i, 4);
             topPanel.add(new JLabel(""), gbc);
          }
          gbc = getGBC(2, 4);
          topPanel.add(new JLabel("Dispatch File =", SwingConstants.RIGHT), gbc);
          gbc = getGBC(3, 4);
          topPanel.add(new JLabel(), gbc);
    
          gbc = getGBC(0, 5);
          topPanel.add(new JLabel("Disposition Port"), gbc);
          gbc = getGBC(1, 5);
          topPanel.add(new JTextField(10), gbc);
          gbc = getGBC(2, 5);
          topPanel.add(new JButton("Open Disposition Port"), gbc);
          gbc = getGBC(3, 5);
          topPanel.add(new JLabel(), gbc);
    
          for (int i = 0; i < 2; i++) { // empty row
             gbc = getGBC(i, 6);
             topPanel.add(new JLabel(""), gbc);
          }
          gbc = getGBC(2, 6);
          topPanel.add(new JLabel("Disposition File =", SwingConstants.RIGHT), gbc);
          gbc = getGBC(3, 6);
          topPanel.add(new JLabel(), gbc);
    
          gbc = getGBC(0, 7);
          topPanel.add(new JButton("Send and Recieve"), gbc);
    
          JPanel bottomPanel = new JPanel(new GridLayout(1, 0, DEFAULT_INSET, 0));
          bottomPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
                .createTitledBorder(BorderFactory.createEtchedBorder(),
                      "Bottom Panel"), BorderFactory.createEmptyBorder(ebGap,
                ebGap, ebGap, ebGap)));
          bottomPanel.add(createTextAreaPanel("Sent"));
          bottomPanel.add(createTextAreaPanel("Received"));
    
          JPanel mainPanel = new JPanel();
          mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
          mainPanel.add(topPanel);
          mainPanel.add(Box.createVerticalStrut(2 * DEFAULT_INSET));
          mainPanel.add(bottomPanel);
    
          mainPanel.setBorder(BorderFactory.createEmptyBorder(ebGap, ebGap, ebGap,
                ebGap));
    
          JFrame frame = new JFrame("SSCCE");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(mainPanel);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       private static JPanel createTextAreaPanel(String text) {
          JPanel taPanel = new JPanel(new BorderLayout());
          JLabel label = new JLabel(text);
          label.setFont(label.getFont().deriveFont(Font.BOLD, TAP_LABEL_SIZE));
          taPanel.add(label, BorderLayout.NORTH);
          int rows = 24;
          int cols = 20;
          taPanel.add(new JScrollPane(new JTextArea(rows, cols)),
                BorderLayout.CENTER);
          return taPanel;
       }
    
       private static GridBagConstraints getGBC(int x, int y) {
          GridBagConstraints gbc = new GridBagConstraints();
          gbc.gridx = x;
          gbc.gridy = y;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.weightx = 1.0;
          gbc.weighty = 1.0;
          gbc.anchor = (x % 2 == 0) ? gbc.WEST : gbc.EAST;
          gbc.fill = gbc.HORIZONTAL;
          int top = DEFAULT_INSET;
          int bottom = DEFAULT_INSET;
          int left = (x > 0) ? DEFAULT_INSET : 0;
          int right = (x < 3) ? DEFAULT_INSET : 0;
          gbc.insets = new Insets(top, left, bottom, right);
          return gbc;
       }
    }
    Last edited by Fubarable; 07-26-2011 at 10:19 PM.
    KevinWorkman likes this.

  13. #13
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Thanks for your help, and I appreciate the time invested.

    At least for now, though, I'm going to leave my utility "ugly" as it's not going to be entered into any beauty contests.

    IMO the Java GUI model is broken or just too darned hard, though. WPF/XAML is more involved than Delphi, but at least is predictable and allows you to see your forms on-the-fly at design time.

    As I expect to spend 90-99% of my Java time with Android, I'm looking forward to what seems like a WPF/XAML-like GUI experience there.

Similar Threads

  1. Moving Components Around
    By SantaFlan in forum AWT / Swing
    Replies: 9
    Last Post: 12-12-2010, 11:08 PM
  2. Different components in an AWT list
    By alinaqvi90 in forum AWT / Swing
    Replies: 10
    Last Post: 08-13-2010, 11:39 AM
  3. placing the components
    By rajeevhegde in forum AWT / Swing
    Replies: 1
    Last Post: 05-17-2010, 04:12 PM
  4. Decent Book For JBuilder 2006
    By MayheM in forum New To Java
    Replies: 2
    Last Post: 08-12-2008, 02:33 PM
  5. Gui Components
    By Marty in forum New To Java
    Replies: 1
    Last Post: 05-28-2007, 05:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •