将文字对准按钮单选框的右侧

时间:2018-09-09 22:58:31

标签: html css html5 css3 flexbox

我有一个主题,下面有此部分,我想在单选按钮的右侧对齐文本,现在在单选按钮的下方对齐

这就是我想要的:enter image description here

这是jsfiddle:http://jsfiddle.net/Mwanitete/Jm2JR/181/

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package business;

import java.awt.BorderLayout;
import java.awt.Color;
import static java.awt.Component.RIGHT_ALIGNMENT;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTree;


/**
 *
 * @author bob
 */
public class NewClass {


    //Initialize GUI elements
    JFrame myFrame = new JFrame();



    JTree jtree1 = new JTree();
    JTree jtree2 = new JTree();

    JLabel label1 = new JLabel("Welcome to the person tester application");
    JLabel label2 = new JLabel("Test2");
    JLabel spacer1 = new JLabel("");
    JLabel spacer2 = new JLabel("");
    //buttons

    JRadioButton radioCustomer = new JRadioButton("Customer");
    JRadioButton radioEmployee = new JRadioButton("Employee");
    ButtonGroup group = new ButtonGroup();
    JButton okButton = new JButton();
    JButton button2 = new JButton("Create");
    JButton button3 = new JButton("EXIT");


    JScrollPane sp = new JScrollPane(jtree1);
    JScrollPane sp2 = new JScrollPane(jtree2);

    //Panels
    JPanel mainPanel = new JPanel(new GridLayout(3,1));
    JPanel panel2 = new JPanel();
    JPanel panel3 = new JPanel(new GridLayout(1,2));
    JPanel panel4 = new JPanel();

    JPanel createPanel = new JPanel();


    //Constructor
    public NewClass(){

    }


    //The createGUI method is inside the class so we can reference the GUI objects created above
    public void createGUI(){

    //Buttons

    button2.setToolTipText("Create");
    button3.setToolTipText("Exit");
    button3.setForeground(Color.red);
    button3.setAlignmentX(RIGHT_ALIGNMENT);
    group.add(radioEmployee);
    group.add(radioCustomer);


    //Adding actionListeners
    GUIListener myListener = new GUIListener();
    okButton.addActionListener(myListener);
    button2.addActionListener(myListener);
    button3.addActionListener(myListener);




    //adding to and customizing the panels


    createPanel.setLayout(new BoxLayout(createPanel, BoxLayout.PAGE_AXIS));
        createPanel.add(radioEmployee);
    createPanel.add(radioCustomer);
    createPanel.add(button2);


    panel2.setLayout(new BoxLayout(panel2, BoxLayout.PAGE_AXIS));
    panel2.add(label1);
    panel2.add(createPanel);



    panel3.add(BorderLayout.CENTER, sp);
    panel3.add(BorderLayout.CENTER, sp2);


    panel4.setLayout(new BoxLayout(panel4, BoxLayout.PAGE_AXIS));
    panel4.add(spacer1);
    panel4.add(button3);





    //adding panels to main panel
    mainPanel.add(panel2);
    mainPanel.add(panel3);
    mainPanel.add(panel4);

    //adding panels we created to the frame


    myFrame.add(mainPanel);



    //setting some parameters to customize the frame

    myFrame.setSize(600, 400);
    myFrame.setLocationRelativeTo(null);

    myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    myFrame.setVisible(true);
}



        public class GUIListener implements ActionListener{
        @Override

        public void actionPerformed(ActionEvent e) {

            if (e.getSource() == okButton){
                label1.setText("okButton was pushed!");

            }
            else if (e.getSource() == button2){

            }


            else if (e.getSource() == button3){


               System.out.println("button3 was pusshed");

            }
        }
    }

    //main method that makes the program run
   public static void main(String[] args) {

       //instantiate an object of the NewClass class
       NewClass GUI = new NewClass();

       //Use the method to create and display the GUI
       GUI.createGUI();
   }

}

我尝试使用float,但是没有用,任何想法或帮助,建议都会被理解,请帮助

1 个答案:

答案 0 :(得分:4)

将此行添加到您的CSS

.resume > div {
   display: flex;
}