java - Centering elements in a BoxLayout -


i cannot lblconinfo center, due it's inline html. know how this?

import java.awt.color; import java.awt.component; import java.awt.dimension; import java.awt.toolkit; import java.io.ioexception;  import javax.swing.boxlayout; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel;  public class streamer extends jframe {     private static string ip = "127.0.0.1";     private static string key = "123456";      public streamer() throws ioexception {         jpanel streampanel = new jpanel();         streampanel.setlayout(new boxlayout(streampanel, boxlayout.y_axis));         setdefaultcloseoperation(jframe.exit_on_close);         setsize(200, 100);         setresizable(false);         dimension d = new dimension(toolkit.getdefaulttoolkit().getscreensize());         setlocation(d.width - 200, 0);         setalwaysontop(true);          add(streampanel);         addcomponents(streampanel);         settitle("rdv");         setvisible(true);         capture.getscreen();     }      public void addcomponents(jpanel pane) {         jlabel lblclipboard = new jlabel("test");         lblclipboard.setforeground(color.blue);         lblclipboard.setalignmentx(component.center_alignment);         pane.add(lblclipboard);          jlabel lblconinfo = new jlabel("<html><div align=\"center\">ip: " + ip + "<br>key:" + key + "</div></html>");         lblconinfo.setalignmentx(component.center_alignment);         pane.add(lblconinfo);          jbutton btncopy = new jbutton("copy clipboard");         btncopy.setalignmentx(component.center_alignment);         pane.add(btncopy);     } } 

add boxlayout.x_axis in constructor of jlabel shown below:

jlabel lblconinfo = new jlabel("<html><div align=\"center\">ip: " + ip + "<br>key:" + key         + "</div></html>", boxlayout.x_axis); 

read more how use boxlayout

snapshot

enter image description here


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -