【发布时间】:2014-07-19 16:38:11
【问题描述】:
我正在制作一个浏览器只是为了练习我的Java技能,有没有办法让我的地址栏是一个JTextField,更大而不是swing的默认值,也更弯曲。这是我的代码。
//imports of the GUI
//import java.awt.*;
//import java.awt.event.*;
//import javax.swing.*;
//import javax.swing.event.*;
//import javax.swing.text.*;
//import javax.swing.GroupLayout.*;
//extends is to use the GUI class
public class ReadFile extends JFrame {
private JTextField addressBar; //to have the address bar
private JEditorPane display; //display the html information
//constructor
//Set the frame icon to an image loaded from a file.
public ReadFile() {
super("SPHERE"); //name of the browser
addressBar = new JTextField("enter an URL", 50); //inside the URL
addressBar.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
loadCrap(event.getActionCommand());
}
}
);
add(addressBar, BorderLayout.NORTH);
display = new JEditorPane();
display.setEditable(false);
display.addHyperlinkListener(
new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent event){
if(event.getEventType()==HyperlinkEvent.EventType.ACTIVATED){
loadCrap(event.getURL().toString());
}
}
}
);
add(new JScrollPane(display), BorderLayout.CENTER);
setSize(600,200);
setVisible(true);
}
//load crap to display on the screen
private void loadCrap(String userText){
try{display.setPage(userText);
addressBar.setText(userText);}catch(Exception e){System.out.println("crap!")}
}
}
我想制作一个真正可用的浏览器,就像我想显示 html 和它的 CSS 页面一样,我还需要学习什么才能使它工作。
【问题讨论】:
-
“曲线”?请详细说明。
-
“我还需要学习什么才能完成这项工作” Swing 对 CSS 和 HTML 的支持有限,您应该研究
JEditorPane的替代解决方案。您可能还想对 SwingLabs 进行一些研究,SwingXPromptSupport -
“我正在制作浏览器只是为了练习我的 Java 技能”
-
如果你看一下 chromes 的多功能框,它的边缘是弯曲的。这就是我的意思。
-
好的,感谢任何回答我问题的人,我真的很感激。我学到了很多新信息。
标签: java javascript css swing jframe