swing

201874040116-李鑫《面向对象程序设计(java)》第十二周学习总结

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-08 02:55:42
内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p/11867214.html 作业学习目标 (1) 掌握Vetor、Stack、Hashtable三个类的用途及常用API; (2) 掌握ArrayList、LinkList两个类的用途及常用API; (3) 了解java集合框架体系组成; (4) 掌握Java GUI中框架创建及属性设置中常用类的API; (5) 了解Java GUI中2D图形绘制常用类的API; 第一部分:总结第九章、第十章理论知识   第九章:      1.java集合框架       1)Java 集合框架主要包括两种类型的容器,一种是集合(Collection),存储一个元素集合,另一种是图(Map),存储键/值对映射。Collection 接口又有 3 种子类型,List、Set 和 Queue,再下面是一些抽象类,最后是具体实现类,常用的有 ArrayList、LinkedList、HashSet、LinkedHashSet、HashMap、LinkedHashMap 等等。       2)集合框架是一个用来代表和操纵集合的统一架构。所有的集合框架都包含如下内容: 接口: 是代表集合的抽象数据类型。例如

What is the difference between registerKeyboardAction(…) and getInputMap().put(…) + getActionMap().put(…)?

落花浮王杯 提交于 2021-02-07 18:46:29
问题 What is the difference between these two methods: getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke( "pressed F10"), "someAction"); getActionMap().put("someAction", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { //Do something } }); and: registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //Do something } }, KeyStroke.getKeyStroke("pressed F10"), JComponent.WHEN_FOCUSED); 回答1: There is no difference,

Making margins smaller - Java Printing

倖福魔咒の 提交于 2021-02-07 18:36:15
问题 I am using this code to print on paper: //Overriden from printable interface public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex != 0) { return Printable.NO_SUCH_PAGE; } Paper a4 = new Paper(); a4.setImageableArea(0, 0, a4.getWidth(), a4.getHeight()); pageFormat.setPaper(a4); pageFormat.setOrientation(PageFormat.PORTRAIT); Graphics2D g2d = (Graphics2D)g; //g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); this

Double icons with JMenuItem setHorizontalTextPosition on Win

爷,独闯天下 提交于 2021-02-07 18:28:38
问题 Two icons are rendered when using JMenuItem setHorizontalTextPosition(SwingConstants.LEFT) with Windows Look and Feel. It works fine with the default Java Look and Feel. I just filed a Java bug report, posting here for anyone else having the same problem. Does anyone have another workaround to suggest? Thanks. import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax

How to debug a swing UI?

最后都变了- 提交于 2021-02-07 14:22:19
问题 I have a Swing screen and I want to debug which services or frames are being used by it. Earlier I have worked on Web apps and there we used used FireBug in firefox mozilla to see how things used in UI and navigate to services. I am new to swing and want to find out how this new application is using it. 回答1: Here is the debug swing is Debugging Swing Applications with the UI Debugger it can be quite useful to debug Swing related application. Another one Visual Debugger provided by NetBeans .

Creating JSplitPane with 3 panels

别等时光非礼了梦想. 提交于 2021-02-07 14:20:10
问题 I would like to create a window, with 3 jPanels, separated by splitPane-s. The left, and the right one should be resizable by the user, and the one in the middle should fill the remaining space. I've created it, but if I move the first splitPane, then the second one is also moving. And I'm not sure, if I use the best method for what I want. import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSplitPane; public class MyWindow extends JFrame {

How do I set different colors for text and underline in JTextPane?

杀马特。学长 韩版系。学妹 提交于 2021-02-07 14:16:58
问题 Just been trying to color the text in JTextPane - but the issue is cannot have different colors for text and the underline. How should I do that or is that even possible? The example below prints all the text and underline in RED. JTextPane pane = new JTextPane(); StyleContext context = new StyleContext(); Style style = pane.addStyle("Black", null); StyleConstants.setAlignment(style, StyleConstants.ALIGN_RIGHT); StyleConstants.setFontSize(style, 14); StyleConstants.setSpaceAbove(style, 4);

How do I implement Ctrl+Z / Command+Z in Java/Swing?

假如想象 提交于 2021-02-07 13:26:56
问题 I'm working on a little Java applet that needs undo/redo functionality. Here's code to set up the hotkeys (works great on Windows). My question is: how do I make it use command+Z on mac? Should I just check System.getProperty("os.name") or is there a more elegant alternative?? private void setupUndoHotkeys() { String UNDO = "Undo action key"; String REDO = "Redo action key"; Action undoAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { undo(); } }; Action redoAction

Single click to edit a JTable Cell

走远了吗. 提交于 2021-02-07 11:26:44
问题 currently the JTable cell is selected on first click, and on the second one it is edited. Is it possible to directly edit it on the first click? 回答1: In the DefaultCellEditor api there is a method named setClickCountToStart DefaultCellEditor singleclick = new DefaultCellEditor(new JTextField()); singleclick.setClickCountToStart(1); //set the editor as default on every column for (int i = 0; i < table.getColumnCount(); i++) { table.setDefaultEditor(table.getColumnClass(i), singleclick); } 回答2:

Java Swing - How to disable a JPanel?

时间秒杀一切 提交于 2021-02-07 11:17:45
问题 I have several JComponent s on a JPanel and I want to disable all of those components when I press a Start button. At present, I am disabling all of the components explicitly by component1.setEnabled(false); : : But Is there anyway by which I can disable all of the components at once? I tried to disable the JPanel to which these components are added by panel.setEnabled(false); but it didn't work. 回答1: The panel should have a getComponents() method which can use in a loop to disable the sub