Results 1 to 13 of 13
  1. #1
    Java2011 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default Which Layout should use for Creating multiline fill in the blanks.

    I am getting a string from database which has a question in the format given below:
    void main(){/n int a,b;\n printf("___",a+b);\n }

    And i have to show this question in format

    void main()
    {
    int a,b;
    printf("<here should be a text box>",a+b);
    }

    There can be more than one fill in the blanks in a row and more than one row can have fill in the blanks.blanks are such that we can drop the choice in the blanks.

    Please help me out.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    ... huh?

    is that to say, you have this kind of encoding to mean "____" is to be rendered when printed as a text field. ?

    what if you encoded the question string stored in the database using some kind of custom HTML or XML, ? that should allow for arbitrary complex input form construction.

    void main(){<br/>int a,b;\n printf("<textfield/>",a+b);<br/><select/><textfield/>}

    and so on ?

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Hard to understand what you are asking.
    For the text use Labels
    For the input area use a TextField
    The text in the labels can span several lines.
    The textfield should be bottom aligned with the label.

    How about a GridBagLayout?

  4. #4
    Java2011 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default how to use html text box for dropping text from java component.

    Can we fire any event on dropping text on the html text field ?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    dropping text on the html text field
    Is this an html question or a java programming question?
    How do you have an html text field in a java program?

  6. #6
    Java2011 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default This is Java Question

    what if you encoded the question string stored in the database using some kind of custom HTML or XML, ? that should allow for arbitrary complex input form construction.

    void main(){<br/>int a,b;\n printf("<textfield/>",a+b);<br/><select/><textfield/>}
    This is the java program , in which question is stored into html format which can be displayed on editor pane.
    now here the question is this if we have text fields in Editor pane can we put any listener so that if we drop answer into that it can fire any event.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Never worked with html in an Editor pane.
    Do you have a small simple program that demonstrates the problem?

  8. #8
    Java2011 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default Editor pane with html text

    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.io.IOException;
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;


    public class DemoEditorPane extends JFrame{

    private JEditorPane ep;
    private String ques;
    private JPanel top,bottom;

    public DemoEditorPane() throws IOException {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension d = tk.getScreenSize();
    setSize(d);
    top = new JPanel(new BorderLayout());
    bottom = new JPanel();
    bottom.setLayout(null);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ques= "<html><body>void main()<br>{<br>int a=10,b=20;<br>printf(\"<input type=text name='1' size=10>\",a+b;<br>}<br></body></html>";
    ep = new JEditorPane();
    ep.setContentType("text/html");
    ep.setEditable(false);
    ep.setText(ques);
    top.add(ep);

    JLabel lblc1 = new JLabel("%d");
    lblc1.setBounds(10, 10, 100, 30);
    bottom.add(lblc1);

    JLabel lblc2 = new JLabel("%f");
    lblc2.setBounds(10, 40, 100, 30);
    bottom.add(lblc2);

    JLabel lblc3 = new JLabel("%c");
    lblc3.setBounds(10, 70, 100, 30);
    bottom.add(lblc3);


    add(top,BorderLayout.NORTH);
    add(bottom,BorderLayout.CENTER);

    setVisible(true);
    }

    public static void main(String ar[]) throws IOException{
    new DemoEditorPane();
    }


    }


    Here in the above program upper panel consists of question and lower panel consists of choices and i want that user can drop the choice in the text in the above question panel.

    i can put transfer handler in the choice label , but how come the text box came to know that string is dropped on them.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Don't know about dropping.
    Have you typed something into the input field and pressed Enter? I get a NPE.
    The stack trace shows a class: FormView that should lead you to how to get at the data entered.

  10. #10
    Java2011 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default

    editor pane is setEditable(false)

  11. #11
    Java2011 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default

    Ok.Html text is the one way to solve this problem.But as you suggest grid bag layout.
    But as i said question is coming from the database and there can be more than one text box required on a single line and there can be more than one line of question.

    So is it not complicated to use grid bag layout.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Why do you need to actually move the answer to the empty slot in the display?
    Wouldn't just selecting the answer/choice be enough?
    Show the question with the place where the answer is to go,
    and show a list of answers.
    The user selects the answer by clicking on it. Drag and drop seems more than is needed.



    Ok, I just saw there is more than one empty slot in a question. More thought required.

  13. #13
    Java2011 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

Similar Threads

  1. To get multiline tooltip
    By diva_garg in forum New To Java
    Replies: 8
    Last Post: 03-25-2011, 04:16 PM
  2. JTable multiline
    By iceT18 in forum AWT / Swing
    Replies: 1
    Last Post: 02-11-2010, 01:02 AM
  3. How to write multiline String in a JLabel
    By JavaBean in forum AWT / Swing
    Replies: 4
    Last Post: 12-14-2009, 05:09 AM
  4. Creating multiline item in JComboBox
    By javabud in forum AWT / Swing
    Replies: 2
    Last Post: 07-17-2009, 03:50 PM
  5. Multiline Regex
    By zriggle in forum New To Java
    Replies: 1
    Last Post: 02-26-2009, 04:49 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
  •