Tag: 用户界面

以前的CardLayoutfunction不起作用?

我的cardlayout的下一个function是正常工作,但以前不是。 就我而言,只需要“layout.previous( _ );” 在我的makePanel()方法的actionPerformed方法体中应该可以工作,但是当我运行我的程序并单击prev按钮时,没有任何反应。 我究竟做错了什么? – import java.awt.*; import javax.swing.*; import java.util.*; import java.awt.event.*; public class Temp { public static void main (String[] args) { new MakeAQuiz(); } static class MakeAQuiz { private JPanel start, base, fields, buttonz, question; private String [] labels = {“Enter your question: “, “Answer 1: “, “Answer 2: “, […]

使用swing组件在框架中打开文本文件

我想使用swing组件在框架中打开文本文件,最好使用突出显示function。 我在第一帧中的文本中获取文本文件的名称,并希望在第二帧中打开文本文件。我的代码是 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class FirstGUI extends JFrame { private JLabel label; private JTextField textfield; private JButton button; public FirstGUI() { setLayout(new FlowLayout()); label = new JLabel(“Enter the file path:”); add(label); textfield = new JTextField(); add(textfield); button = new JButton(“Open”); add(button); AnyClass ob = new AnyClass(); button.addActionListener(ob); } public class […]

IntentService冻结了我的应用程序UI

在我的应用程序中,我使用Intentservice从服务器获取数据并将获取的数据存储到本地sqlite db。 我正在使用5个IntentService来获取和填充五个表。 每个Intent Service的数据最多可达300行。 我该怎么办? IntentService代码: public class SendBpRecordServer extends IntentService { DbHelper dbHelper; public static final String TAG=”BP Service”; public JSONObject finalData; public SendBpRecordServer() { super(“BP”); dbHelper=new DbHelper(this); Log.i(“In Constructor”,TAG); } @Override protected void onHandleIntent(Intent intent) { String recName=intent.getStringExtra(“nameTag”); if (recName.equals(“fetch”)) { Log.i(“Send Data”,”Yes”); fetchDatFromServer(); ResultReceiver resultReceiver=intent.getParcelableExtra(“receiverTagBP”); Log.d(“BP Reseult “,resultReceiver.toString()); Bundle bun= new […]

如何使主GUI线程“等待”,直到单独的弹出窗口消失

我有一个从主GUI线程调用的对象,并显示一个单独的JFrame几秒钟然后消失(使用一个计时器)。 现在我想让主GUI线程等到弹出的JFrame窗口消失。 例如,在主GUI代码上: // initiate the object and show the pop-up JFrame DisappearingJFrame djf = new DisappearingJFrame (); djf.show (); // now the main GUI thread should wait // and after the pop-up JFrame disappears, the rest of the code is then executed … … 任何建议都会受到欢迎。 谢谢。

以随机顺序显示CardLayout卡?

我想在CardLayout中随机下载显示卡片或屏幕的顺序。 我需要有关如何实现这一目标的指导。 我应该使用什么策略? 我尝试使用下面的代码,但它是按固定顺序。 我希望能够选择我喜欢的订单。 编辑! 对不起,按随机顺序我并不是说洗牌。 但是,很高兴知道。 我希望程序的用户能够输入一些输入。 根据输入的值,显示特定的屏幕/卡。 import java.awt.*; import javax.swing.*; import java.awt.event.*; public class CardLayoutExample extends JFrame { private int currentCard = 1; private JPanel cardPanel; private CardLayout cl; public CardLayoutExample() { setTitle(“Card Layout Example”); setSize(300, 150); cardPanel = new JPanel(); cl = new CardLayout(); cardPanel.setLayout(cl); JPanel p1 = new JPanel(); […]

SceneBuilder中的JavaFx StackPane,如何只显示前窗格而不设置禁用其他人的可见性?

相关问题: 节点 – 选择要显示JavaFX2的图层 我正在使用带有SceneBuilder 2的JavaFx 8.我有许多窗格作为StackPane的子窗口,我想只显示前端节点。 我需要在不禁用其他孩子的可见性的情况下执行此操作,并且我尝试使用下面看到的不透明度设置执行此操作(忽略可见性已禁用的事实): 在不禁用其他子节点的可见性的情况下,即使使用不同的混合模式(SRC_OVER和SRC_ATOP),子节点也总是相互绘制,如下所示: 我想避免将子元素的可见性设置为false的原因是我想要在窗格之间设置过渡动画,其中一个窗格需要在另一个窗格的顶部绘制。 我必须在这里遗漏一些明显的东西,但我看不出它是什么?

如何将组件动态添加到Java JScrollPane

我试图用Java创建一个GUI应用程序,但是我在JScrollPane中动态添加/更新组件时遇到了麻烦。 我有两个JPanel(P1和P2),其中P1有一个表单来设置应用程序的参数,P2包含一些GUI组件,它们根据P1中的值动态更新。 我需要在P2上滚动JScrollPane,所以我在P2中添加了JScrollPane。 我将P1和P2添加到主面板“main”,然后将主面板添加到框架中。 但是P2中没有更新组件。 有人可以提出什么问题吗? 我调用了revalidate(),repaint()和其他一些方法,但GUI没有更新。 下面是我编写的示例代码,用于说明我的问题。 我在我的应用程序中需要GroupLayout,所以在这里我也使用了GroupLayout import java.awt.event.ActionEvent; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; public class JframeExample extends JFrame { private final JPanel P1; private final JPanel P2; private final JPanel main; private final JScrollPane scrol; private final JButton jButton; private final JButton jButton2; public JframeExample() { P1 […]

如何使用Timer动态调整帧大小?

我正在尝试使用Timer对象动态调整窗口大小,但没有成功…我在构造函数中设置了面板的首选大小,它很好地设置了窗口的大小,但只有一次。 程序初始化后首选大小会更改,但窗口大小保持不变。 为什么? 因为构造函数只初始化一次,因此不受大小变化的影响? 如果是这样,我怎么能绕过这个来实时调整窗口大小? 我知道这不会解决开头评论中给出的练习中的问题,所以请忽略它:-) /* * Exercise 18.15 * * “(Enlarge and shrink an image) Write an applet that will display a sequence of * image files in different sizes. Initially, the viewing area for this image has * a width of 300 and a height of 300. Your program should continuously shrink […]

将字体导入GUI

我试图更改我的GUI的字体,除了基本的5,摇摆似乎随附。 如何导入字体并在我的代码中实际使用它们?

在cardlayout中切换卡后运行方法

我确定之前有人问过这个问题,但今天我的google-fu并不强大。 我有一个使用CardLayout作为其管理器的JFrame。 当我在不使用开关的情况下切换到每个JPanel时,如何运行“开始”方法? 我用来将帧添加到布局的代码是: /** * Adds JPanels to the Card Layout. * @param panel is the JPanel to add to the layout. * @param windowName is the identifier used to recognise the Panel. */ public final void addToCards(final JPanel panel, final WindowNames windowName) { view.getBasePanel().add(panel, windowName.getValue()); } 我用来切换布局的代码是: /** * Method to change the […]